Dear developers,
please revise the gui for Project Settings->Graphics->Preload Shaders
My project uses the GLTFast package to load 3D models at runtime. I want to allow users to add their own models made in Blender.
This worked fine in the editor, but failed to load the required shaders at runtime.
Following the manuals and AI guidance, I am told to create a shader variants asset (which I did using the button in Projects Settings->Graphics).
Then I was told to add this asset to the preloaded shaders by dragging it into the list. What list? All I could see was a field that said there was 0 preloaded shaders.
After much experimentation and hair pulling, I realised that I needed to manually change this 0 to 1. Doh!
I could then drag my asset variant bundle into the field thus revealed.
Prior to working this out, I tried adding the required shader to the always include list. It took a while to realise that the GLTF shader I needed was in the hidden shaders. I also discovered that I needed to save the project in order for that setting to be used by the build. This at least got the shader to compile, but not load.
Anyway, with the shader in both the always include and in the preloaded shaders, it now works.
I possibly need to prune some of the loaded shaders but, for the moment, I’ll leave well enough alone.
I’m using Unity Editor 6.2 (6000.2.13f1)<OpenGL 4.5) which the latest hub seems to indicate is the latest editor for Ubuntu Linux.
You don’t need to do that… I’m pretty sure what you’re looking at is a standard Unity collection display, where you can drag new stuff into the label name and it will expand and add to the end. Try it now! Drag a second shader onto the label name and it should add.
Personally I don’t like dragging stuff into there if I can avoid it. The reason is that it is far too “out of sight” to me.
When I need shaders to be included I just make a material out of them and drag an instance of the shader into a Scene that I know gets included in the build. Low tech but easy, since I often have a “static assets” additively-loaded scene for various parts of my games to make sure assets are loaded and don’t cause hitching when first loaded.
I also almost NEVER use Shader.Find(); as I think it is just as dangerous as GameObject.Find();
Remember the first rule of GameObject.Find():
Do not use GameObject.Find();
More information: Regarding GameObject.Find · UnityTipsRedux
In general, DO NOT use Find-like or GetComponent/AddComponent-like methods unless there truly is no other way, eg, dynamic runtime discovery of arbitrary objects. These mechanisms are for extremely-advanced use ONLY.
If something is built into your scene or prefab, make a script and drag the reference(s) in. That will let you experience the highest rate of The Unity Way™ success of accessing things in your game.
“Stop playing ‘Where’s GameWaldo’ and drag it in already!”
Here’s why all this stuff is CRAZY code:
Thank Kurt-Dekker
Dragging a shader collection onto the “Preload Shaders” label worked exactly as you advised.
I didn’t think to try that. I don’t think of labels as active objects except for tooltips. I would have expected a plus button or similar to indicate an empty list.
I agree with your “out of sight” sentiment. The many hidden settings in Unity frightened me away from it for many years.