Search Unity

Simple animation during loading = NOT possible in Unity ?!?!

Discussion in 'Editor & General Support' started by flekoun, Apr 26, 2012.

  1. flekoun

    flekoun

    Joined:
    Jul 13, 2010
    Posts:
    51
    Hello,
    We are currently porting our game on iOS and our distributor require to display some kind of animation when the loading in longer than 1 sec so the player don't think that the game is frozen. Dead simple and very common thing to see everywhere in games. Player click play and want to see for example animated beach ball, three dots blinking together or whatever. What was our shock to discover that all mighty Unity 3D engine is totally incapable of doing such a basic thing. We don't even need any kind of progress bar. We just want to show simple 2 frame animation or whatever what is "life". Can anyone give us the advise? Because as everyone know the the Application.LoadLevelAsync is nice but useless because it finishes loading in few milliseconds and returs DONE. But after that the initialization of a scene takes another 10 seconds. But during those 10 seconds you can't do anything! We would love to be able to have a second thread where we could refresh the loading animation at least. But this is not possible in Unity. We bought Unity Pro just because of this feature ...loading level asynchronously.... but it is not working. Nothing helped. Disabling the GO in the scene and then enabling them one after another. Didn't help. Additive loading and Additive loading async. Didn't help same problem as LoadLevelAsync. Nothing. I am shocked that we cannot do this dead simple thing in Unity whatever we do. Just an animated "beach ball" during loading. Thats all I want from professional game engine. Please can someone give me a hint how is this possible??? I am desperate.


    Here you can see the problem with Application.LoadLevelAsync described into more detail if someone don't know what I am talking about.
    http://answers.unity3d.com/questions/61598/how-to-preload-a-scene-with-progress-bar-so-it-can.html
     
    Last edited: Apr 29, 2012
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    It doesn't work with resources.load. So if you do any crap like that you'll still have to wait, including setup. A lot of things are blocking, so it's pretty obvious you'd need to restructure for it to work out for you.
     
  3. flekoun

    flekoun

    Joined:
    Jul 13, 2010
    Posts:
    51
    Hi Hippocoder,
    we do not use Resource.Load at all. Nor the assetBundles.

    Just to show how LoadLevelAsync fails to do what it probably was meant to do, consider this example.
    I have two scenes. Both contain just one gameObject. Each having just one script on it.
    Scene1 does nothing just loading Scene2.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class LoadingScript : MonoBehaviour {
    5.    
    6.     int i = 0;
    7.    
    8.     IEnumerator Start() {
    9.         AsyncOperation op = Application.LoadLevelAsync("Scene2");
    10.         Debug.Log("Loading STARTED");
    11.         while (!op.isDone) {
    12.             i++;
    13.             Debug.Log("Loading " + i);//just to see when async load is done
    14.             yield return 0;
    15.         }
    16.         Debug.Log("Loading DONE");
    17.     }
    18. }
    Scene2 does even less.

    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class NothingScript : MonoBehaviour {
    4.    
    5.     public GameObject prefab;
    6.    
    7.     void Start() {
    8.         Debug.Log("Object STARTED");   
    9.     }
    10. }

    If I did not reference any prefab to the 'NothingScript' everything is done in no time. However if I reference a really big prefab to the 'prefab' of 'NothingScript' it works this way:

    After starting the Scene1 in editor I immediately get:

    Loading STARTED
    Loading 1
    Loading 2

    .... then I wait 6-10 seconds ....

    Object STARTED

    It obviously loads the big prefab and stops everything and I can not play even the simplest of the loading animations.
    And therefore I state LoadLevelAsync() does not work correctly. Or do I miss something?

    Note: that really big prefab is of no use. In real we do not have such big prefabs. I created it just for showing that even this does not work, so how can I expect anything more.
     
  4. diablo

    diablo

    Joined:
    Jan 3, 2011
    Posts:
    736
    I'm curious... what if you did this :

    Code (csharp):
    1.  
    2.     IEnumerator Start()
    3.     {
    4.         AsyncOperation op = Application.LoadLevelAsync("Scene2");
    5.         Debug.Log("Loading STARTED");
    6.         yield return op;
    7.         Debug.Log("Loading DONE");
    8.     }
    9.  
    and then put the Debug output in the Update() method... does it still stop printing output at "Loading2"?
     
  5. flekoun

    flekoun

    Joined:
    Jul 13, 2010
    Posts:
    51
    Hi Diablo,
    I did as you ask for:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class LoadingScript : MonoBehaviour {
    5.    
    6.     int i = 0;
    7.    
    8.     IEnumerator Start() {
    9.         AsyncOperation op = Application.LoadLevelAsync("Scene2");
    10.         Debug.Log("Loading STARTED");
    11.         while (!op.isDone) {
    12.             yield return op;
    13.         }
    14.         Debug.Log("Loading DONE");
    15.     }
    16.    
    17.     void Update() {
    18.         i++;
    19.         Debug.Log("Loading " + i);//just to see when async load is done
    20.     }
    21. }
    Unfortunately the debug is exactly the same as before:

    Loading STARTED
    Loading 1
    Loading 2
    .... 6sec lag....
    Object STARTED

    I can't believe that this basic thing that should be available in any game engine is not present in Unity. Even the Shadowgun uses static Loading screen. This is Hilarious!
     
  6. JRavey

    JRavey

    Joined:
    May 12, 2009
    Posts:
    2,377
    This is my suggestions, take it or leave it.

    When you swap scenes, actually load *two* scenes. The first being your loading scene with a front-end camera that blocks the view. Think of it as your curtain. Then additively load your scene in the background, but don't sweat that camera until you're ready to display it. Then when the background scene is actually ready to go, remove your object which was acting as your stage curtain along with its associated camera.
     
  7. flekoun

    flekoun

    Joined:
    Jul 13, 2010
    Posts:
    51
    Hi JRavey,

    thanks for your solution. This is one of the solutions how to show the static loading screen. However this not solve our problem. We need some kind of animated loading screen. In your case you when I load the first "curtain" camera the loading bar can be animated but as soon as I start additively loading the actual scene the game freezes and I am back with static loading screen for 10 seconds.
     
    Zinov likes this.
  8. JRavey

    JRavey

    Joined:
    May 12, 2009
    Posts:
    2,377
    Are you loading it additively and asynchronously?
     
  9. flekoun

    flekoun

    Joined:
    Jul 13, 2010
    Posts:
    51
    Yes sure even when we use Application.LoadLevelAdditiveAsync(). Thats the whole point. Async loading is useless.
     
  10. Gorgor

    Gorgor

    Joined:
    Apr 28, 2012
    Posts:
    51
    Hi I have similar problem flekoun described -> Async loading is not async at all.
    And according to the silence here I suppose that none here actually ever needed animated loading screen and all use static one - if any. Is it a Unity bug? Does it ever worked?
     
  11. flekoun

    flekoun

    Joined:
    Jul 13, 2010
    Posts:
    51
    Ok. So can any developer finally confirm here that Application.LoadLevelAsync is useless and animation during scene loading is impossible in Unity engine? I would love to know this for sure. Thanks.
     
  12. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,660
    Run the profiler; it should record the spike in frame time at the point where you get a pause. What does it say the time's being spent on?
     
  13. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,660
    FWIW, I'm using LoadLevelAdditiveAsync(), and I do get a pause at the end of loading but I think it's mostly down to my Awake() methods.

    Also, last I checked, it simply doesn't work in the editor. Test it in builds only.
     
  14. Divide!

    Divide!

    Joined:
    Aug 4, 2011
    Posts:
    7
    The Async stuff doesn't work in the Unity editor, only when you make a build (at least I know this to be true for PC builds). Unity loads up all the objects in the background, but once it's done it will call Awake on everything at the same time, so you might get a performance hiccup depending on how many objects and the complexity of your awake method.
     
  15. diablo

    diablo

    Joined:
    Jan 3, 2011
    Posts:
    736
    Hey flekoun, would you confirm that it works (or doesn't) as expected when you build it? Apparantly the issue only manifests itself when run from the editor.
     
  16. flekoun

    flekoun

    Joined:
    Jul 13, 2010
    Posts:
    51
    Thanks all for your advices. We tried to make a build and to our surprise the Async loading is working! Shame on me for not trying to actually make a build and try it. We didn't expect that this feature is not working in editor as there isn't any note about it. So for everyone who will be looking into this thread in a future: Async loading is working but only in the build NOT in editor! Thanks again guys!
     
    Zinov likes this.
  17. They Call Me Steve

    They Call Me Steve

    Joined:
    Jun 29, 2012
    Posts:
    1
    It saddens me that Unity Scripting Reference doesn't explain that at all. Would have been nice to have that information with the function so that I didn't chase a problem for an hour and a half with such a simple answer.
     
    Damjan-Mozetic and Zinov like this.
  18. komodor

    komodor

    Joined:
    Jan 2, 2013
    Posts:
    36
    looks like dead thread but...

    all this trouble is because of scene initialization, not just awake and it's the same in editor and runtime

    still not fixed, you guys in unity should think about asynchronous scene initialization, this is ridiculous in 2018 :D i am in editor opening level 15 minutes just because it has lots of sprites animations and it takes just a few seconds of the time until the progress gets to the 0.9 and then it takes ages (in runtime it's much better but still there just like one percent of the time used for loading and then it's just frozen until it's ready

    I guess you have to think about reworking the whole animator core to do stuff just in time or provide other solution because the way it works now is really annoying ...