Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shader value always null #393

Closed
MarnixKuijs opened this issue Apr 5, 2019 · 10 comments
Closed

Shader value always null #393

MarnixKuijs opened this issue Apr 5, 2019 · 10 comments

Comments

@MarnixKuijs
Copy link

When trying to export any model the exporter always gives an exception that Shader value cannot be null when creating a new material.

error

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?

@andreasplesch
Copy link

andreasplesch commented Apr 24, 2019

I have the same issue, using the latest Unity (2019.1) with the latest unitypackage release on Linux.

@andreasplesch
Copy link

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 ?

@andreasplesch
Copy link

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.

@AdamMitchell-ms
Copy link
Contributor

@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.

@andreasplesch
Copy link

@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 ?

@dblatner
Copy link

dblatner commented Jun 6, 2019

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:
image

Can you help me to solve this? I think then it might work for importing GLTF from a URL.

@JakobCh
Copy link

JakobCh commented Oct 15, 2019

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?

@andybak
Copy link

andybak commented Apr 5, 2020

Yep. Still getting this one year after the initial report. Is anyone actually using this?

@tacopancakes
Copy link

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!!!

@pfcDorn
Copy link
Contributor

pfcDorn commented Feb 9, 2024

Please update to the latest version and open a new issue if the problem persists. Thanks!

@pfcDorn pfcDorn closed this as completed Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants