Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question 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:
    393
    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:
    393
    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:
    393
    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.
     
    julienkay likes this.
  4. ArshakKroyan

    ArshakKroyan

    Joined:
    Mar 4, 2015
    Posts:
    32
    Hey @Stranger-Games, Thank you for sharing your founding.
    These are really helpful.

    I previously had a problem related to Prefab auto loading.

    Today by accession I found LazyLoadReference and thought that could fix Prefab loading issue.
    Started researching more about this class and found your thread :).
    In your thread I found also AssetReference.

    Thank you very much.