Search Unity

Question Assets loaded when they shouldn't be, like in the main menu - Trying to reduce start up time.

Discussion in 'Editor & General Support' started by whidzee, Aug 2, 2022.

  1. whidzee

    whidzee

    Joined:
    Nov 20, 2012
    Posts:
    166

    I am looking at reducing the time it takes for my game to load from the splash screen to the main menu. Our main menu isn't super complicated single 3d model, skybox and some ui elements.

    When I run the memory profiler I see a ton of assets loaded like large textures and what not, all of which are used in our maps, but not in the main menu. about 660mb of textures are loaded, and 99.99% of those aren't in the main menu.

    I like that they are being loaded into memory as it likely helps speed up the loading of the maps, but is there a way for them to load in the background so that the main menu can load up faster?

    I'm sure I am missing something small
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,411
    if they are inside Resources folder, i think they get all loaded..
    or maybe some script references them?
     
  3. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,859
    Nah they don't get loaded. But the Resources look-up table does get deserialised at start, which can take a while depending on how many assets are in said folder(s).

    But as you said, if anything in any way references them, they will enter member. This includes scriptable objects. It could be a reference chain dozens of steps removed, but it will still bring the assets into memory.

    Does the memory profiler show how they're referenced?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    Subtle detail: they CAN get loaded... here's how:

    If you do a
    Resources.LoadAll<T>()
    at some point in your resources folder hierarchy (eg, the collected combined final result), then Unity actually does:

    - load EVERY resource it finds into memory
    - see if it is a <T>
    - add it to a final list if it is

    This means a Resources.LoadAll<Widget>( ""); will load EVERYTHING, even if you only have a single Widget somewhere.

    This is why it is important to use subdirectories, such as a
    MyWidgets/
    directory:

    Resources.LoadAll<Widget>( "MyWidgets/");
    will ONLY load every asset in that folder trying to see if it is a Widget or not.

    Or start using Addressables; I find Addressables still a little overkill for my simple needs, but we use them at work and they are (I'm told) the future, although I'm always skeptical of such "the fyooture" claims, given how much abandoned technology has happened in the past five years (Anima2D, remote config, just to name two things).