Search Unity

WaitForSeconds stops working for values above approx 480

Discussion in 'Scripting' started by Virt_Arch, Jul 18, 2016.

  1. Virt_Arch

    Virt_Arch

    Joined:
    Oct 19, 2015
    Posts:
    6
    I'm using WaitForSeconds as part of a coroutine for rate limiter in a script calling external APIs. The call is being made inside the IEnumerator with WWW and the yield function.

    The script works fine for values in the range 1 to 480 seconds. However, I want to pause my api call for 10 minutes or 600 seconds. For values above 480 seconds (I've only tried values close to 540 and 600) the repeat call doesn't get made.

    Is there a limit on the number of seconds I can specify?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class OpenWeatherMapReader : MonoBehaviour {
    5.  
    6.     IEnumerator ReadWeather() {
    7.                 while (true) {
    8.             string weatherUrl = "http://api.openweathermap.org/data/2.5/weather?id=2643743&APPID=APIKEYHERE";
    9.  
    10.             WWW weatherWWW = new WWW (weatherUrl);
    11.             yield return weatherWWW;
    12.  
    13.             JSONObject tempData = new JSONObject (weatherWWW.text);
    14.             Debug.Log(tempData);
    15.  
    16.             JSONObject weatherDetails = tempData["weather"];
    17.             string WeatherType = weatherDetails[0]["main"].str;
    18.             Debug.Log(WeatherType);
    19.  
    20.             yield return new WaitForSeconds(600);
    21.         }
    22.     }
    23.  
    24.     void Start () {
    25.         StartCoroutine (ReadWeather());
    26.     }
    27. }
     
  2. Dave-Carlile

    Dave-Carlile

    Joined:
    Sep 16, 2012
    Posts:
    967
    What happens if you remove all of the web code and just do a Debug.Log call? So just the while loop, debug call, yield for 600 seconds? Probably in a completely new Monobehaviour to make sure nothing else in your project is interfering.

    Is there some other code that might be cancelling the Coroutine? Is the monobehaviour being disabled somewhere?

    I've never heard of a time limit, but that doesn't mean there isn't one. Worst case you can wake up once a minute, increment a minute counter, then do the web request once your counter reaches 10, reset the counter to 0.
     
    landon912 likes this.