Search Unity

Addressables question

Discussion in 'Addressables' started by florinel2102, Jul 8, 2020.

  1. florinel2102

    florinel2102

    Joined:
    May 21, 2019
    Posts:
    76
    Hi , sometimes I use Addressables for speed and better memory management , but I don't really understand
    when I have to release an asset .
    E.g If i have to instantiate multiple prefabs and I create a simple scriptable object which have an array of gameobjects which I mark as addressable and I load ,, after instantiate prefabs , can I release the object or can I release just only after I don't need prefabs . Thanks for your time .

    Code (CSharp):
    1.  
    2.     private void Test()
    3.     {
    4.         var load = Addressables.LoadAssetAsync<Prefabs>("Objects"); // Prefabs it's a simple scriptable object
    5.  
    6.         await load.Task; //wait for load
    7.  
    8.         var objects = load.Result; // get result
    9.  
    10.         for(int i = 0; i < 5; ++i)
    11.         {
    12.             Instantiate(objects.prefabs[i]); //instantiate prefab
    13.         }
    14.  
    15.        Addressables.Release(load); // or just after i don't use prefabs anymore
    16.  
    17.     }
     
  2. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    586