- Home /
SetPropertyBlock for CanvasRenderer?
I wrote a custom shader for a floating health bar, world UI element, and noticed that setting properties on it was setting it for all objects using that material.
I found mentions of Renderer.SetPropertyBlock through some searches for how to fix that issue, but CanvasRenderer doesn't include the SetPropertyBlock function.
Is there some work around or other method of dealing with this issue? Not being able to set the shader values in UI materials seems like a pretty big oversight.
All I could find related to this issue for specifically UI was this unanswered question from last year: http://answers.unity3d.com/questions/940525/how-to-set-pre-render-properties-to-ugui-image.html
Answer by Ryetoast · Apr 08, 2016 at 08:00 PM
Ended up finding a good solution from Reddit. Just Instantiate a new instance of the material object in Start().
Image imageComp = GetComponent<Image>();
imageComp.material = Instantiate(imageComp.material);
Popping in to say this is a great solution for the propertyBlock problem on Canvas'. Thanks!
I don't recommend this. Every new material will increase SetPass calls by one.
Your answer
Follow this Question
Related Questions
Changing two different objects renderer colour 1 Answer
Select material of Canvas Renderer 0 Answers
Weird rendering on Android: some materials become black, some sprites are replaced 1 Answer
Display a world-space canvas to overlay all the meshes but not the other UI objects 0 Answers
Changing Shaders HDR Color results in different Color. 1 Answer