Search Unity

SOLVED All level assets loading on level select screen - causing memory issues

Discussion in 'Editor & General Support' started by hugeandy, Nov 10, 2016.

  1. hugeandy

    hugeandy

    Joined:
    Nov 2, 2016
    Posts:
    131
    Hi all,

    We have been working on our game for quite a while now and are ramping up into testing at the moment. The first major problem we have come across is memory pressure issues on iPhones and upon further investigation we have discovered that all textures from all levels are being loaded on our level select screen.

    The way we have our game structured is as follows:
    A LevelObject ScriptableObject per level which stores:
    -Level info such as name, time limit etc
    -A reference to a prefab which has that levels specific GameObjects in it

    The LevelSelect screen then has a grid of buttons, each of which has a reference to the LevelObject for the corresponding level. This is used to display information about the level before going into it. When you select to load a level, you get taken to a skeleton scene which has all the GameObjects common to all levels already in it, and it Instantiates the prefab referenced in the LevelObject.

    I believe the memory problem comes from the fact that Unity/C#/Mono has to have everything that is referenced to be loaded into memory. So the LevelObject on each button in the level select scene means each levels prefab is referenced, leading to every component in every level is referenced, and therefore is loaded. This really doesn't seem right!

    We took this approach as having a scene for each level was too much to change if we wanted to add/remove/change an element which is common in each level.

    Maybe having a scene for each level which is loaded over the top of the skeleton scene using additive scene loading would be a solution? But I'd like to get some expertise from here before converting to that!

    Any advice would be greatly appreciated

    Cheers!
    Andy
     
  2. hugeandy

    hugeandy

    Joined:
    Nov 2, 2016
    Posts:
    131
    Converting them to scenes solved the problem very well