Author Topic: UIProgressbar.value and Yield don't work together?!  (Read 1928 times)

Biggix

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 33
    • View Profile
UIProgressbar.value and Yield don't work together?!
« on: December 25, 2014, 06:44:43 PM »
Another issue which is driving me crazy.

I'm using a very simple coroutine to update gradually a value of an UIProgressBar.

  1. var go = GameObject.Find ("ProgressBack");
  2. UIProgressBar uil = go.GetComponent<UIProgressBar> ();
  3. float add=0.01f;
  4. float st=0f;
  5.  
  6.         for (var h=1; h<=20; h+=1) {
  7.                        
  8.                         uil.value =st+(add*h);
  9.                        
  10.                         yield return new WaitForSeconds (0.05f);
  11.                        
  12.                 }

The same code is used to adjust the value of a money counter in another similar IENumerator so it works and it is not the issue of the code itself.

It's something with the UIProgressbar. When I put debug info, it's clear the "for" cycle is executed only once for some unknown reason (instead of 20 times).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIProgressbar.value and Yield don't work together?!
« Reply #1 on: December 30, 2014, 02:32:07 PM »
How do you launch this coroutine? You need to explicitly start it. There are no issues updating a progress bar from a coroutine.

Biggix

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 33
    • View Profile
Re: UIProgressbar.value and Yield don't work together?!
« Reply #2 on: December 30, 2014, 10:59:41 PM »
I found out that it's not NGUI, it's some strange Unity behaviour. Under certain conditions, Unity stops a coroutine upon the very first yeild. I can't define a pattern on when this happens but I already encountered this twice. Had to do a workaround both times.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIProgressbar.value and Yield don't work together?!
« Reply #3 on: December 31, 2014, 03:57:45 PM »
Oh yeah, I've ran into that obscure issue once too... if you can figure out what causes it to happen, I'd love to know.