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. Dismiss Notice

Question Few questions regarding Addressable & Resources loading

Discussion in 'Scripting' started by Nvizzio_Steven_G, Aug 7, 2023.

  1. Nvizzio_Steven_G

    Nvizzio_Steven_G

    Joined:
    Jan 24, 2023
    Posts:
    6
    Hello! This is for work, to help me better understand the pipeline and address (pun intended) an issue we're having.

    I have a few questions that I have had conflicting answers to on the internet or chatGPT etc

    1. If an asset is outside of resources folder, not in a bundle, has no links directly to it whatsoever, is it permanently loaded in memory?

    2. Same as question #1, but the difference now is I have a ScriptableObjet in Resources referencing said asset (which is still not in resources btw), and that scriptable is loaded via resources.load, but I am not making any calls to the aformentioned asset yet in code. Is the asset loaded anyway?

    3. What happens to an asset that is both in a bundle and also in the resources folder. I would assume it is bundled, but does it have another copy in resources?

    Thank you for your answers
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,769
    It will be loaded into memory whenever anything in an any active scene directly references it (or through any number of dependencies) and will be unloaded when nothing is referencing the asset any more.

    Again, any direct references are loaded into memory once the parent asset is loaded as well. However in this case, your asset will probably be duplicated at build, as the SO in resources - I believe - will cause one copy to be built into the Resources asset bundle, and another will be built into the game's general bundles, if it's used outside the SO.

    You will also have two copies of the asset here.

    So it goes without saying if you plan to use addressables or asset bundles you need to plan asset organisation accordingly.

    The addressables analyse window can also give you a report of assets that will be duplicated.