Search Unity

Do I need to remove subscription from completed event once the event has been completed?

Discussion in 'Addressables' started by mnarimani, Jul 11, 2019.

  1. mnarimani

    mnarimani

    Joined:
    Mar 27, 2017
    Posts:
    212
    Here is my code:
    Code (CSharp):
    1.         public static void InstantiatePrefab(string id, Transform parent, GameObjectLoadCallback callback)
    2.         {
    3.             void OnCompleted(AsyncOperationHandle<GameObject> obj)
    4.             {
    5.             }
    6.  
    7.             AsyncOperationHandle<GameObject> handle = Addressables.InstantiateAsync(id, parent);
    8.             if (callback != null)
    9.             {
    10.                 handle.Completed += OnCompleted;
    11.             }
    12.         }
    Do I need to remove OnCompleted method from Completed event subscriptions after the async operation has been completed?
     
  2. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    308
    No need. The system will cache the handle via a result-to-handle dictionary internally. As long as you invoked Addressables.Release (or when the scene get destroyed), the handle will be released with the instantiated object (the result).
     
    mnarimani likes this.