question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Shader value always null

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
andreaspleschcommented, Apr 25, 2019

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 ?

3reactions
andreaspleschcommented, Apr 25, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I use If or is NULL statement in Shader Graph? ...
There is no such thing as a null in a shader. Well, there is, but it just crashes the GPU if it exists....
Read more >
unity Shader returns a NULL when using Shader.Find
First, go to unity editor: Edit->Project Settings-> Graphics Then in the inspector where it says "Always Included Shaders" add ...
Read more >
I have unity telling me the code isn't working because I can' ...
That tells you Shader.Find("Hidden/BWDiffuse") is returning a null value. The best way to handle this is probably to add a Shader variable ......
Read more >
What is a 0 "null" normal map? Or Unlit shader
1 Answer. In the most common normal map encoding, an RGB value of (0.5,0.5,1) would be uniformly flat. If the shader is meant...
Read more >
Null Reference Exceptions
A NullReferenceException happens when you try to access a reference variable that isn't referencing any object. If a reference variable isn't referencing an ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found