SetPropertyBlock for CanvasRenderer?
Asked Answered
C

2

0

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

Craner answered 5/11, 2023 at 21:30 Comment(2)

my positive i up and my alt positive is w

Lisabeth

Could you put the error log?

Sebrinasebum
C
0

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);
Craner answered 6/6, 2023 at 2:40 Comment(5)

Popping in to say this is a great solution for the propertyBlock problem on Canvas'. Thanks!

Hypoglossal

I don't recommend this. Every new material will increase SetPass calls by one.

Brisesoleil

Great solution, works perfect.

Artilleryman

the arrows does not work? didi you also tried to Debug.Log(Input.GetAxis("Vertical")); to check if there weren't any other problems? Maybe the problem is in your animator...

Sebrinasebum

Fire_cube is correct, try printing a message to see if anything shows. Also select your animator that you're setting the float for and in the animator tab see if that float is changing at all.

Dunlavy
H
0

Popping in to say this is a great solution for the propertyBlock problem on Canvas’. Thanks!

Hypoglossal answered 28/8, 2017 at 2:32 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.