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

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

    Guest

    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?
     
    Royce17 and Zaddo like this.
  2. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    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).