Author Topic: Strategies for avoiding freezes on scene load?  (Read 9436 times)

Aki Kanerva

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Strategies for avoiding freezes on scene load?
« on: July 25, 2014, 08:15:48 AM »
Hi,

We have a menu with a large number of NGUI components. It runs perfectly smoothly during usage, but when loading the scene, the game freezes for 1-2 seconds while all the OnEnable, Awake and Start functions run. The freeze time goes past the platform's maximum requirement - and anyway, it looks silly because we're supposed to be showing a loading screen animation during the time.

Are there ways of spreading this out over a longer period of time to allow a decent frame rate? Unity's own LoadLevelAsync is quite good at this, but it's limited to loading assets. Once everything has been loaded (which actually only takes less than a second), there's a lot of code that gets executed that causes the freeze.

Thank you.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Strategies for avoiding freezes on scene load?
« Reply #1 on: July 26, 2014, 12:37:35 AM »
You can enable parts of your UI at a time, or just reduce the amount you have on the screen. Why do you have so much stuff there that it takes 2 seconds to activate? Where is the time actually spent? Are you performing anything on startup?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Strategies for avoiding freezes on scene load?
« Reply #2 on: July 27, 2014, 07:00:09 PM »
Make a loadscene that loads a simplified UI with only a loading screen in it, then you won't fall into the trap of "device max load time" since your game is technically loaded.

Once the load scene is shown, either load a new scene asynchronously or synchronously with your full game in.

Aki Kanerva

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Strategies for avoiding freezes on scene load?
« Reply #3 on: July 28, 2014, 07:04:33 AM »
We have a scrollable map that contains all of the game's levels (55 in total), including level number, icon, player's best time, two par times, and various sprites showing whether or not level-specific goals were reached. Due to an uncommon control method, it's not possible to show this information piecemeal. The total number of NGUI widgets is very high, but as I mentioned, there are no issues at runtime. The map is larger than the screen, so not all of the widgets are always visible (but they still need to wake up to begin with). The 1-2 seconds I mentioned is the sum of time spent on OnEnable(), Awake() and Start() calls on NGUI widgets, mostly sprites and labels.

We already have a load screen. This is not an issue of maximum load time, it's about the frame rate freezing for the time it takes to call Awake() and Start() on a large number of GameObjects that are mostly NGUI widgets, because this isn't asynchronous. The loading screen animation does not advance during this time.

I managed to split the loading somewhat by making each submenu into a prefab, then having a coroutine instantiate them, one per frame. This alleviates the problem a bit, but the map is by far the biggest of the submenus - the others take only a few milliseconds to initialize. It looks like I'll need to somehow split the map into segments as well.