Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: rvm8i on February 17, 2015, 10:25:01 PM
-
Hi everyone,
I'm trying to change a property of a UITexture's material (UITexture instantiated from a prefab) using GetComponent<UITexture>().drawCall.dynamicMaterial.SetFloat(). When I have only one instance, it behaves exactly as I'd expect. However, when I instantiate more, it seems like all the instances start using the same material. I remember reading somewhere that each UITexture comes with its own internal material - I assume I'm not accessing this one? If that's the case, how would I get each instance of my prefab to change the properties of its own material?
Thanks!
rvm8i
-
NGUI batches all UITextures that use the same texture into a single draw call. This means that if you have 5 UITextures, they will share exact same draw call.
You need to use different textures or different materials for them to not get batched.
P.S. You should be using UIWidget.onRender -- that's where you should be setting the material properties.
-
Thanks, I got it working! I ended up cloning the material using the constructor that creates a duplicate, then assigning that to be the UITexture's material. The tip about assigning a delegate to onRender was really helpful too :)
Cheers,
rvmi8