- Home /
Setting Material Tag at runtime for replacement shader tricks
Hello, Does anyone know how to set a Material's Tag at runtime?
With this code, I can determine the value of a tag at runtime:
var materialTag = "RenderType";
var result : String = renderer.material.GetTag(materialTag, true, "Nothing");
Unfortunately, there is no Material.SetTag() function. Are there any other ways to set the tag of a material at runtime? (Other than changing the material's shader through scripting.)
http://unity3d.com/support/documentation/ScriptReference/Material.GetTag.html This could be very useful when dealing with replacement shaders.
http://unity3d.com/support/documentation/Components/SL-ShaderReplacement.html
Still to this day, this isn't possible and this is exactly what I need to do with the new Unity 5 Standard Shader.... :(
Answer by Ross_B · Oct 05, 2016 at 01:42 PM
"Will set a tag/value on the material that overrides the value of said tag from the shader."
material.SetOverrideTag("TagKey", "NewTagValue");
@Kovenant According to the docs It looks like you could use this to set any standard shaders "RenderType" tag.
While you can use this to allow objects with existing materials to be rendered selectively, It doesn't look like its possible to do a replacement with dynamic values on both sides, since you pass a Shader, not a Material to the respective replacement functions.