Author Topic: UILabels don't update during WWW call  (Read 3613 times)

Pojo226

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
UILabels don't update during WWW call
« on: September 27, 2013, 12:50:27 PM »
Hello,

I'm trying to use a progress bar (UISlider) with a text label (UILabel) to show progress during a coroutined WWW import. If I don't try to update the label, the progress bar and debug statements update as the data loads, but while trying to update the label, it freezes everything until the import is done. My guess is that the progress bar updates as it is just affecting the scale of the foreground element, while the text actually needs to be calculated. I've tried calling the label's update geometry (inherited from UIWidget) but that didn't work. I assume that the geometry itself is received during the panel's draw call?

If anyone has advice for this, or if I'm just going about it completely wrong, all feedback is welcomed.

And if anyone would like a look at code, here's a small bit of the first part. I modified UISlider to have a UILabel variable so I could modify associated text through progress bars:

  1. using(WWW import = new WWW("file://" + pathToFile)){
  2.         while(!import.isDone){
  3.                 progressBar.sliderValue = import.progress;
  4.                 progressBar.textField.text("LOADING " + import.progress / import.size + "/" + import.size);
  5.                 progressBar.textField.UpdateGeometry(progressBar.textField.panel, true);
  6.                 Debug.Log("Import: " + import.progress);
  7.                 yield return new WaitForEndOfFrame();
  8.         }
  9. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabels don't update during WWW call
« Reply #1 on: September 27, 2013, 01:30:18 PM »
Uh. You should never be calling UpdateGeometry yourself. Ever. It's a function used by the panel class, and it's meant to be used in a specific order.

Furthermore, what are you doing using the text string as a function? It's not a function. All you need to do is this:
  1. using(WWW import = new WWW("file://" + pathToFile)){
  2.     while(!import.isDone){
  3.         progressBar.sliderValue = import.progress;
  4.         progressBar.textField.text = "LOADING " + import.progress / import.size + "/" + import.size;
  5.         yield return new WaitForEndOfFrame();
  6.     }
  7. }

Pojo226

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: UILabels don't update during WWW call
« Reply #2 on: September 27, 2013, 02:07:04 PM »
Sorry- I did have the text assignment how you said. I was quickly mashing together some copy + pastes and that got screwed up.

After I import the file, I can update the label just fine in the same coroutine (separated by WaitForEndOfFrame's). In the while loop I can get the progress bar to update, but only when trying to update the text field with it Unity freezes until the import is completed.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabels don't update during WWW call
« Reply #3 on: September 27, 2013, 06:25:34 PM »
May be some conflict with dynamic fonts then. You are likely requesting new characters from it and it has to wait until the loading process finishes before it can fulfill your request.

FizzPow

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
    • FizzPow Games
Re: UILabels don't update during WWW call
« Reply #4 on: October 02, 2013, 09:06:56 PM »
Are you sure you can access WWW.size at that time?  It's not even a documented property.  Just curious, have you tried without that?