Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Loading bar - async.progress not working?

Discussion in 'Scripting' started by kjetilh, Sep 20, 2011.

  1. kjetilh

    kjetilh

    Joined:
    Oct 1, 2010
    Posts:
    82
    Hi!

    I'm trying to setup a simple loadingbar using async loading and using the progress value from the async load operation.

    I've tried several ways of setting this up and after reading a bit about it I ended up with something like this:

    Code (csharp):
    1. AsyncOperation async = Application.LoadLevelAsync("0Menu");
    2. Debug.Log("Start Loading);
    3.  
    4. while(!async.isDone)
    5. {
    6.      Debug.Log("loading...");
    7.      progressbar.value = async.progress;
    8.  
    9.      yield return null;
    10. }
    So, I now get a few "loading.." printed out, but the async.progress always returns zero.

    I start this as a coroutine in Start.

    I read some places that the progress property might be broken? Is this true?
    If so I guess I will have to stick to something that just animates a bit while the scene is loading.

    Btw, I do have unity pro.

    k.
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,602
    in some parts its broken yes.

    also that you have pro is clear, async loading is pro only ;)
     
  3. Rush-Rage-Games

    Rush-Rage-Games

    Joined:
    Sep 9, 2010
    Posts:
    1,998
    Yep, make sure you have pro. ;)
     
  4. kjetilh

    kjetilh

    Joined:
    Oct 1, 2010
    Posts:
    82
    Yes heh. Thats why i mentioned that i had pro. So that people wouldn't spend any effort telling me to get pro :p but ok. I can make a progress icon of sorts. Something that just animates.

    I plan to do this by instantiating a prefab containing a backdrop and a progress bar (from excellent ez gui).
    The i set it to do not destroy on load, load the scene async while animating something. Then when the scene is loaded i can have a "tap to continue" message displayed.

    Anyway, at least i know that there are known bugs, so i can focus effort somewhere else :)

    Thanks!

    Kjetil
     
  5. JonnyHilly

    JonnyHilly

    Joined:
    Sep 4, 2009
    Posts:
    741
    ever get this working ?
    I have similar issue.. async loading appears be.... well... only partially async...
    rendering seems to stop during async loading, then continues after loading.

    Trying to just draw some regular moving gui textures... bouncing ball etc....
    It prints 30 or so debug messages during the loading... but doesn't update the screen.

    This is both on iOS-pro and Mac-pro unity
    any ideas ?
     
    Last edited: Oct 1, 2011
  6. Fixdit

    Fixdit

    Joined:
    Nov 6, 2010
    Posts:
    17
    Also experiencing identical issue.
     
  7. JonnyHilly

    JonnyHilly

    Joined:
    Sep 4, 2009
    Posts:
    741
    Update:-
    it is actually working, but strangely only on the device, not on PC or Mac.
    maybe it just loads too fast on PC/Mac
     
  8. kjetilh

    kjetilh

    Joined:
    Oct 1, 2010
    Posts:
    82
    yep, it was quite erratic on the mac, but worked ok on the iphone.

    I just instantiate a loading screen where I have various controls.
    I have an icon there which is automatically set to animate when it's created.
    And this just runs while I load, and I remove it and wait for input when it's all done.
    I get input, fade out the screen, and destroy the object afterwards.

    Kindof rough but it seems to work ok..
    Code (csharp):
    1.  
    2.  
    3. public void InitLoadScreen(string screenToLoad, bool tap)
    4.     {
    5.         string textureToLoad = "Textures/LoadingScreens/" + screenToLoad;
    6.         TextAsset locationDescription = (TextAsset)Resources.Load(("Textures/LoadingScreens/" + screenToLoad + "Desc"));
    7.         backdrop.renderer.material.mainTexture = (Texture2D)Resources.Load(textureToLoad);
    8.         descriptionText.Text = locationDescription.text;
    9.         loadScreenPanel.Reveal();
    10.         StartCoroutine(LoadLevel(screenToLoad, tap));
    11.     }
    12.    
    13.  
    14. IEnumerator LoadLevel(string screenToLoad, bool tap)
    15.    {
    16.       yield return new WaitForSeconds(1.0f);           // Wait until we did the fade out before we load.
    17.       Debug.Log("Loading " + screenToLoad);
    18.           async = Application.LoadLevelAsync(screenToLoad);
    19.      
    20.          while(!tapped)
    21.          {
    22.          if(async.isDone) // Level finished loading.
    23.          {
    24.             if(!tap)
    25.                 tapped = true;
    26.             animatedIcon.Hide(true);
    27.             tapToContinue.controlIsEnabled = true; 
    28.          }
    29.            
    30.          yield return null;
    31.         }
    32.        
    33.        Destroy(this.gameObject, 1.0f);
    34.        loadScreenPanel.Dismiss();
    35.    }
     
unityunity