Search Unity

A way to wait for something?

Discussion in 'Unity Build Automation' started by Uli_Okm, Oct 5, 2018.

  1. Uli_Okm

    Uli_Okm

    Joined:
    Jul 10, 2012
    Posts:
    95
    Is there any way to do a Wait for something during the build process?
    For instance, I would like to wait for a WebRequest upload during the postprocess step, but I can't create a coroutine in the editor; And when I simply start uploading my files apparently the cloud build unity just closes and the uploads aren't completed.

    Is there any way to do this? Even if it must be a static predefined amout of time (maybe 60 seconds, or something like this), only to guarantee that the upload was sucessfully completed

    Thanks
     
  2. ollieblanks

    ollieblanks

    Unity Technologies

    Joined:
    Aug 21, 2017
    Posts:
    460
    Hi @Uli_Okm,

    Something like this should work.

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using UnityEngine.Networking;
    4. using Debug = UnityEngine.Debug;
    5.  
    6. public static class CloudBuildHelper
    7. {
    8.    public static void PostExport()
    9.    {
    10.       IEnumerator e = Upload();
    11.      
    12.       // While loop invoking MoveNext on enumerator
    13.       while (e.MoveNext());
    14.    }
    15.    
    16.    static IEnumerator Upload() {
    17.       byte[] myData = System.Text.Encoding.UTF8.GetBytes("This is some test data");
    18.       UnityWebRequest www = UnityWebRequest.Put("https://www.YourServerAddress.com", myData);
    19.       yield return www.SendWebRequest();
    20.  
    21.       // Wait until the upload is done
    22.       while (!www.isDone)
    23.          yield return true;
    24.      
    25.       if(www.isNetworkError || www.isHttpError) {
    26.          Debug.Log(www.error);
    27.       }
    28.       else {
    29.          Debug.Log("Upload complete! " + www.responseCode);
    30.       }
    31.    }
    32. }
    33.  
    Hope that helps!
     
    crekri, henriqueranj and Uli_Okm like this.