Author Topic: UITexture Materials  (Read 2046 times)

rvm8i

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
UITexture Materials
« 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITexture Materials
« Reply #1 on: February 17, 2015, 10:56:28 PM »
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.

rvm8i

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: UITexture Materials
« Reply #2 on: February 18, 2015, 07:11:51 PM »
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