Search Unity

using WWW when timeScale is near 0?

Discussion in 'Scripting' started by Joe ByDesign, Apr 22, 2008.

  1. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Is this possible? If so, what is the secret?

    As I can see, yielding for WWW result data doesn't work when timeScale is near 0 and thus it's not possible to say "get scores while paused" :(

    Is there a yield equivalent that isn't dependent on timeScale?
     
  2. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    OK, here ya go:

    Code (csharp):
    1. function Start() {
    2.     yield WaitForRealTimeSeconds(1.0);
    3.     print ("1 real second has passed no matter what the time scale is!");
    4. }
    5.  
    6. function WaitForRealTimeSeconds (delay : float) {
    7.     yield WaitForSeconds(delay * Time.timeScale);
    8. };
    No charge. ;)

    Anyway, yeah, looks like yielding for WWW doesn't like really low timeScale numbers here either. Bug?

    --Eric
     
  4. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    :oops:

    Thanks Eric, you're so right! :)

    The funny thing is that I wrote my own time management class with which I can do my own time-scaling (I needed that for my server which has to manage different timescales simultanuously for different game sessions). But simply writing my own subclass of WaitForSeconds was beyond my imagination ;-)

    Cool, that solves another issue I was having :)

    Sunny regards,
    Jashan
     
  5. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    So I guess the answer is no? :p
     
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    That wouldn't help if the timeScale is 0, or if the timeScale changes while it's waiting. A more robust function might look like:

    Code (csharp):
    1.  
    2. function WaitForRealTimeSeconds(duration : float) {
    3. var started : float = Time.realtimeSinceStartup;
    4. while (Time.realtimeSinceStartup < started+duration) yield;
    5. }
    6.  
    (untested!)

    ....actually, I may put that on the wiki....
     
  7. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    That's a cool utility, and I might be just missing it, but I don't see how that has anything to do with using WWW when timeScale is near 0.

    Wanting to yield to a return on the WWW call, sure I can just wait a few seconds and test, but it's not really the same as waiting for the data.
     
  8. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Right, you're yielding on the result of WWW, not WaitForSeconds or anything else.

    I guess there is a bug with that, but as a workaround you could write a loop (or coroutine) to keep polling for data and calling a callback function when/if the data finally clears. Just remember to code a timeout.

    Still clunky, but it might be all you can do for now.

    Seems odd that WWW would be in any way based on the timeScale though...

    HTH,
    -Jeremy
     
  9. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Yes this is what I was referring to by "wait a few seconds and test". It all seems very strange given the nature of the internet, but it is all I can do when paused apparently.