Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Standalone not responding while loading scene

Discussion in 'Editor & General Support' started by Sycobob, Jun 10, 2015.

  1. Sycobob

    Sycobob

    Joined:
    Feb 1, 2013
    Posts:
    78
    I stumbled across something troubling recently that I really don't know how to solve and I'm hoping for some insight here.

    We have some quite large scenes in our game with many objects. When our largest scene is loaded from disk, there is a period of time where Windows believes the game has stopped responding. If the user clicks with their mouse during this time Windows will present the usual "application has stopped responding" dialog



    This is bad user experience when nothing is actually wrong and the game is just loading. The immediate reaction is going to be that the game is broken and to close it. At the very least, it appears unprofessional.

    This occurs when loading the particular scene from Application.LoadLevelAsync, or right after the Unity splash screen when making a build with just this scene. Both development and non-development builds. It occurs before Awake is called for any script, so it appears not to be code related (though could be serialization related). It occurs if loading from disk takes a long time for any reason: resource contention, slow hardware, large scene, etc. Since we have a very large scene, this happens regularly even on an SSD with little to no resource contention.

    It's very easy to reproduce this behavior with any moderately sized scene by simply playing a build from a USB 2 flash drive.

    How can we stop this from happening? It seems this should be considered a bug in the engine.

    Unity 5.0.2f1
     
    Last edited: Jun 10, 2015
  2. Sycobob

    Sycobob

    Joined:
    Feb 1, 2013
    Posts:
    78
    I've narrowed this down silghtly. It only occurs when the game is running in a window. It happens when running Fullscreen Windowed, or in a bordered window, but it does not occur when running in fullscreen Exclusive Mode. I've tested on D3D 9 and 11.
     
  3. dizzy2003

    dizzy2003

    Joined:
    Nov 25, 2013
    Posts:
    97
    Yes we have this too, didnt realise the windowed mode was affecting it.

    Have you submitted a bug?
     
  4. Sep200

    Sep200

    Joined:
    Jul 29, 2013
    Posts:
    13
    Same issue, there's always an "x is not responding" pop up when Unity standalone builds are loading or exiting large scenes.
     
  5. maclark86

    maclark86

    Joined:
    Jan 21, 2016
    Posts:
    6
    same issue, any updates?
     
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I'd bet money that async loading the scene would avoid the issue.
     
  7. Sycobob

    Sycobob

    Joined:
    Feb 1, 2013
    Posts:
    78
    Yea, that'll likely hide the issue for most people. I'm assuming application code and the windows message pump both run on the same thread. So any blocking operation you do from the main thread will eventually cause this. Async loading still has a stall when it runs OnEnable and friends on everything in the scene, but assuming you're not doing something insane it's probably short enough to avoid tripping windows' "not responding" behavior. Back in the day I found it to be a much better practice to avoid OnEnable, OnDisable, etc and do your own setup/teardown so you can control how long you block. Better still to do setup from another thread, but you can't use most Unity API from other threads so it's mostly a wash.
     
  8. Simunek

    Simunek

    Joined:
    Jul 15, 2016
    Posts:
    48
    I have this problem now. Rewriting level loading did not help (I am using async).

    So... The screen resolution and fullscreen modes solve the problem? Thanks.
     
  9. thanhle

    thanhle

    Joined:
    May 2, 2013
    Posts:
    162
    I have the same problem ... has anyone solved this problem ?
    i am using unity 2019.2 .... upgrade to 2020 can be resolve?
     
  10. Nikolat93

    Nikolat93

    Joined:
    Sep 5, 2016
    Posts:
    36
    Anyone have a solution? I've never seen it happen on my computer regardless of window setting but it happens on other computers all the time. Unity 2019.4.1f1 here
     
  11. Simunek

    Simunek

    Joined:
    Jul 15, 2016
    Posts:
    48
    Hi, I am fighting with that to this day. There are 2 suspects:

    1) Music audio (you have to convert it to OGG and then play with import settings)
    2) When using transform.parent = .... on you should use SetParent(..., false);

    But this only reduces the number of crashes, so I really don't know...

    Do you have any other ideas? Cheers!
     
  12. Simunek

    Simunek

    Joined:
    Jul 15, 2016
    Posts:
    48
    So... Setting import settings to "Compressed in Memory" helped me a lot.
     
  13. Nikolat93

    Nikolat93

    Joined:
    Sep 5, 2016
    Posts:
    36
    Yes it makes a huge difference! Glad this worked for you
     
  14. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    If the problem is caused by loading 1 large scene async, you could also consider splitting that scene into several smaller scenes, which you load one after the other. Since any asset referenced within a scene is loaded with the scene, also eliminate any references to assets you aren't using, or if just not using immediately you could move them around so you load them later closer to when they are needed.

    On large audio assets, especially large music files, set loadInBackground to true for all of them other than the music you're playing first. This will allow a scene which references them to finish loading and start playing before the audio assets have actually finished loading from disk. (that's also why you leave this disabled for the first song, if you want it to be playing with the start of the scene)

    https://docs.unity3d.com/ScriptReference/AudioClip-loadInBackground.html
     
    Last edited: Feb 26, 2021
  15. Nikolat93

    Nikolat93

    Joined:
    Sep 5, 2016
    Posts:
    36
    Thank you there is some good advice here. In my case I have a main hub that always needs to be spawned in, but then I also have a bunch of prefabs with references to assets that need to be instantiated but not immediately. I think that moving these prefabs to a different scene and loading them additively would help with the initial load time a lot.
     
    Joe-Censored likes this.