Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Help Wanted Reference prefab without loading it in memory

Discussion in 'Prefabs' started by Stranger-Games, Aug 18, 2020.

  1. Stranger-Games

    Stranger-Games

    Joined:
    May 10, 2014
    Posts:
    332
    Hi,

    When you assign a prefab in the inspector, it would normally load once the scene is loaded taking up memory even if it's not instantiated until later.

    I am pretty sure there was a new feature in some Unity version where you can assign the prefab in the inspector but only load it when you need it, then you can instantiate it after you manually loaded the prefab in code.
    I forgot the feature's name but I need to use it now.
    I searched for the feature but I can't find it even though I am sure I read about it somewhere.

    Thanks for advance.
     
  2. Stranger-Games

    Stranger-Games

    Joined:
    May 10, 2014
    Posts:
    332
    Edit
    -----
    Actually no, I was wrong. LazyLoadReference does not seem to be used in monobehaviors. I do remember something similar used in monobehaviors.
    ----------------------------------------------------
    I think I found it.
    LazyLoadReference can be used for that.
    But I feel like there was another feature similar to this that gives you more flexibility with loading/unloading.
    There doesn't seem to be a way to unload LazyLoadReference asset after it's loaded.
    Is there such a feature?
     
    Last edited: Aug 19, 2020
  3. Stranger-Games

    Stranger-Games

    Joined:
    May 10, 2014
    Posts:
    332
    I finally found it.
    It's AssetReference!
    Explanation on how to use it for lazy loading found here.
    Finally!
    I thought I was getting crazy.
     
unityunity