Author Topic: UITexture - no automatic Update after SetFloat to the material  (Read 3160 times)

imakemygame

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
UITexture - no automatic Update after SetFloat to the material
« on: November 02, 2013, 05:40:29 AM »
Hello guys,
I use NGUI 3.0.2

I have a UITexture with a material which I want to change on runtime.

  1. manaBubbleMat = transform.FindChild("MagicBubble").gameObject.transform.FindChild("mpBar").transform.GetComponent(UITexture).material;
  2. manaBubbleMat.SetFloat("_Cutoff", manaInPercent);

But it seems that there is no automatic Update//drawcall of the material. Sometimes, e.g. some colliders triggers, then the material updates//drawcalls
The editor shows the changed material. I mean I can see the changed Cutoff. But not it does not change ingame. Hope you can understand what I mean. My english is not the best

Regards Martin

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITexture - no automatic Update after SetFloat to the material
« Reply #1 on: November 02, 2013, 08:07:12 AM »
UIWidget.drawCall.dynamicMaterial

imakemygame

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: UITexture - no automatic Update after SetFloat to the material
« Reply #2 on: November 02, 2013, 12:18:06 PM »
Ok how can I use your line?

If I try
  1. manaUITexture = transform.FindChild("MagicBubble").gameObject.transform.FindChild("mpBar").transform.GetComponent(UITexture);
  2. manaUITexture.drawCall.dynamicMaterial -> is null
I get an "Object reference not set to an instance of an object" error

I tried to set my material but it does not work because the dynamicMaterial is only read

So please how do I have to use what you tell me?
« Last Edit: November 02, 2013, 12:38:25 PM by imakemygame »

imakemygame

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: UITexture - no automatic Update after SetFloat to the material
« Reply #3 on: November 02, 2013, 04:56:03 PM »
Ok the thread can be closed. The problem was, that the drawCall.dynamicMaterial was null because I have to wait for one or two frames. Now I just ask if(drawCall.dynamicMaterial != null) and then it runs !