Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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

Discussion in 'Addressables' started by Deleted User, Jul 11, 2019.

  1. Deleted User

    Deleted User


    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.             }
    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


    Apr 4, 2011
    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).
    Deleted User likes this.