Author Topic: UITexture only changes texture on first instance of prefab  (Read 4810 times)

kjenkins_oculus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
UITexture only changes texture on first instance of prefab
« on: November 01, 2013, 07:04:34 PM »
I have a prefab with a UITexture. I instantiate it 4 times. On each of the 4 instances I call a script on the prefab to change the texture using the WWW class and a URL.

Each of the 4 instances downloads the texture, then runs the code to change it.

  1. uiTextureComponent.material = new Material(uiTextureComponent.material.shader);
  2. uiTextureComponent.mainTexture = downloadedTexture2D;
  3.  

However, the first texture changes 4 times in quick succession, while the other 3 remain black. Through breakpoints I have confirmed that each of the 4 instances is downloading its own texture. It's like the material or texture is shared among all instances when it should not be.

Thanks for the help.

kjenkins_oculus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: UITexture only changes texture on first instance of prefab
« Reply #1 on: November 01, 2013, 07:09:22 PM »
I tried setting the texture to nothing as specified in this thread
http://www.tasharen.com/forum/index.php?topic=3613.msg17836#msg17836

It did not fix the problem. Doing that only displays the "Color Tint" value.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITexture only changes texture on first instance of prefab
« Reply #2 on: November 01, 2013, 08:25:10 PM »
UIWidget.drawCall.dynamicMaterial is what you should be altering. Texture material is only what the drawn material gets created from.

kjenkins_oculus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: UITexture only changes texture on first instance of prefab
« Reply #3 on: November 04, 2013, 01:47:00 PM »
UIDrawCall does not have a member dynamicMaterial.

kjenkins_oculus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: UITexture only changes texture on first instance of prefab
« Reply #4 on: November 04, 2013, 01:57:50 PM »
I found the problem, it was not nGUI. I was using a string based callback but every instantiated game object had the same name.