UnityGLTF
UnityGLTF copied to clipboard
Shader value always null
When trying to export any model the exporter always gives an exception that Shader value cannot be null when creating a new material.
The error lies in GLTFSceneExporter.cs line 90
line 90: var metalGlossChannelSwapShader = Resources.Load("MetalGlossChannelSwap", typeof(Shader)) as Shader;
line 91: _metalGlossChannelSwapMaterial = new Material(metalGlossChannelSwapShader);
line 92: var normalChannelShader = Resources.Load("NormalChannel", typeof(Shader)) as Shader;
line 93: _normalChannelMaterial = new Material(normalChannelShader);
This is on the latest release. Any idea on how I can make it work?
I have the same issue, using the latest Unity (2019.1) with the latest unitypackage release on Linux.
For me the root problem was that I used https://github.com/KhronosGroup/UnityGLTF/releases/download/v1.0.1/UnityGLTF.unitypackage to add GLTF capability to a new, existing project. It turns out that this is not enough. The gltf export also needs a copy of the Resources folder from the repo or source.zip (https://github.com/KhronosGroup/UnityGLTF/archive/v1.0.1.zip) to be available in the project's Assets folder. Without it line 90 in GLTFSceneExporter.cs does not find the "MetalGlossChannelSwap" shader resource and Resources.Load returns null (should there be guard ?). So just copying that Resources folder into the project's Assets folder should fix this issue.
Ultimately, that is a packaging issue since neither UnityGLTF.unitypackage nor the upm package at https://github.com/KhronosGroup/UnityGLTF/releases/download/v1.0.1/org.khronos.UnityGLTF.zip currently contain the Resources folder although they probably should. In other words, it might work to move the Resources folder into the Assets/UnityGLTF folder, in the repo ?
I moved the Resources folder into Assets/UnityGLTF folder in this branch: https://github.com/andreasplesch/UnityGLTF/tree/linux-build The built unity package: UnityGLTF.unitypackage.zip works now also for exporting gltf after being imported into a project.
@andreasplesch , it sounds like you have a fix in your fork. Can you create a pull request so we can get this fix into master? Once this change and pull #406 go in, it might be a good time to create a new release.
@AdamMitchell-ms , my linux-build branch moved the Resources folder into Assets/UnityGLTF but also has a number of linux specific changes:
- removed Tests from solution (blocker): hard to build on linux
- mono specific path in GLTFSerialization.csproj: could include logic to deal with all platforms
- correct capitalization in UnityGLTF/UnityGLTF-dll.csproj: necessary on linux, not sure why it seems to work on MacOSX
Unfortunately, I do not have a way to build and test on MacOSX or Windows.
Do you still want me to PR, perhaps for cherry picking ?
Hey @andreasplesch , I tested your Unity package on MacOSX with Unity 2019.1.3.
There are some absolute paths pointing towards your local machine, I got this error:
JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0. Newtonsoft.Json.JsonTextReader.ParseValue () (at <1fa899c21f554672afbc630cc93b185e>:0) Newtonsoft.Json.JsonTextReader.Read () (at <1fa899c21f554672afbc630cc93b185e>:0) GLTF.Schema.GLTFRoot.Deserialize (System.IO.TextReader textReader) (at /home/andreas/Downloads/UnityGLTF-linux2/UnityGLTF-linux-build/GLTFSerialization/GLTFSerialization/Schema/GLTFRoot.cs:274) GLTF.GLTFParser.ParseJson (System.IO.Stream stream, GLTF.Schema.GLTFRoot& gltfRoot, System.Int64 startPosition) (at /home/andreas/Downloads/UnityGLTF-linux2/UnityGLTF-linux-build/GLTFSerialization/GLTFSerialization/GLTFParser.cs:54) UnityGLTF.GLTFSceneImporter+<LoadJson>d__52.MoveNext () (at Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs:497) --- End of stack trace from previous location where exception was thrown --- System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <1f0c1ef1ad524c38bbc5536809c46b48>:0) System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0) System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0) System.Runtime.CompilerServices.TaskAwaiter.GetResult () (at <1f0c1ef1ad524c38bbc5536809c46b48>:0) UnityGLTF.GLTFSceneImporter+<LoadSceneAsync>d__43.MoveNext () (at Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs:232) --- End of stack trace from previous location where exception was thrown --- System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <1f0c1ef1ad524c38bbc5536809c46b48>:0) System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0) System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0) System.Runtime.CompilerServices.TaskAwaiter.GetResult () (at <1f0c1ef1ad524c38bbc5536809c46b48>:0) UnityGLTF.GLTFComponent+<Load>d__16.MoveNext () (at Assets/UnityGLTF/Scripts/GLTFComponent.cs:127) --- End of stack trace from previous location where exception was thrown --- System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <1f0c1ef1ad524c38bbc5536809c46b48>:0) System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0) System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0) System.Runtime.CompilerServices.TaskAwaiter.GetResult () (at <1f0c1ef1ad524c38bbc5536809c46b48>:0) UnityGLTF.GLTFComponent+<Start>d__15.MoveNext () (at Assets/UnityGLTF/Scripts/GLTFComponent.cs:50) --- End of stack trace from previous location where exception was thrown --- System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <1f0c1ef1ad524c38bbc5536809c46b48>:0) System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0) UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at /Users/builduser/buildslave/unity/build/Runtime/Export/Scripting/UnitySynchronizationContext.cs:115) UnityEngine.UnitySynchronizationContext:ExecuteTasks()
And here a screenshot:

Can you help me to solve this? I think then it might work for importing GLTF from a URL.
Still getting this with the latest unitypackage on Unity 2019.2.8f1 Just seams like MetalGlossChannelSwap.shader and NormalChannel.shader are missing from the release? Or maybe the whole Resources folder is supposed to be in there?
Yep. Still getting this one year after the initial report. Is anyone actually using this?
I added all shaders from the resources and the gltfutility plugin im using to the Always include shaders list Player settings > Graphics > Always include works on Oculus quest 2!!!
Please update to the latest version and open a new issue if the problem persists. Thanks!