Hi
I packed my shader and ShaderVariants file in one assetbundle and build.
If the material is created in the editor and assigned to an object, there should be no issue with displaying the shader effect properly.
m_SpriteRenderer.sharedMaterial.EnableKeyword("HITEFFECT_ON");
If the material is dynamically created at runtime and then assigned to an object, the shader effect may not work properly.
Material mat = new Material(Shader.Find("AllIn1SpriteShader/AllIn1SpriteShader"));
m_SpriteRenderer.sharedMaterial = mat;
m_SpriteRenderer.sharedMaterial.EnableKeyword("HITEFFECT_ON");
Could you please help to check the question, Thanks!
Hi!
If you intend to switch keywords on materials at runtime, they should be declared using #pragma multi_compile
instead of #pragma shader_feature
. The latter determines the variants automatically based on existing materials that go into the build. If you create one using a script, the variant may not be present.
4 Likes
Thank you for help! I got it!
I recently got AllIn1SpriteShader and have been having a similar issue where some material properties (namely “_GrassManualToggle” and “_GrassManualAnim”) modified at runtime aren’t updating until I expanded the properties in the inspector - I’ve tried enabling those keywords in code, but it does not fix the issue.
The issue’s different from yours as I’m not creating the material during runtime, but I’ve searched all over without finding a fix
So you’re my only hope haha.
Have you run into similar issues?
1 Like