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

Trouble understanding resource loading. Can someone enlighten me?

Discussion in 'Scripting' started by 0xsven, Sep 26, 2015.

  1. 0xsven

    0xsven

    Joined:
    Mar 5, 2015
    Posts:
    18
    Hi,

    so I am working on this game that has a randomly generated world. It also has different themes for the world. Only one theme is being used at the same time in the game. I put all theme files into the reosurces folder. This is the file structure I am using:

    Assets/
    - Resources/
    - - Themes/
    - - - DesertTheme/
    - - - - Materials/
    - - - - Prefabs/
    - - - - Options/
    - - - WinterTheme/
    - - - - Materials/
    - - - - Prefabs/
    - - - - Options/
    - - - AnotherTheme/
    - - - - ...
    - - - - and so on...​

    My problem with that is: All files are constantly loaded into memory. I want to only have the currently used theme in memory. If i for testing remove all themes but the one that is active from the resources folder, I will save 60mb on my iPhone. Which is a lot.

    This is how I am loading the theme stuff:

    // Load all prefabs of the desert theme
    Resources.LoadAll("Themes/Desert/Prefabs");

    // Load specific material
    Resources.Load("Themes/Desert/Materials/sand");
    I tried Resources.UnloadUnusedAssets() but there was no effect.

    How do I load only the themes I am actually using into memory?
    What might have caused those files to load?
     
    Last edited: Sep 26, 2015
  2. 0xsven

    0xsven

    Joined:
    Mar 5, 2015
    Posts:
    18
    *bump*
     
  3. Hacky

    Hacky

    Joined:
    Mar 22, 2013
    Posts:
    28
    Kiwasi likes this.
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Asset bundles are the way to go. They behave in a similar fashion to the resource folder. But you can choose which assets to load, and when.