Search Unity

[Bug] Multi-scene and SetParent breaks ReleaseInstance

Discussion in 'Addressables' started by Artanic, Aug 19, 2018.

  1. Artanic

    Artanic

    Joined:
    Nov 26, 2012
    Posts:
    9
    Not 100% sure if this is a bug or a design limitation.

    When you instantiate an object in one scene and then use SetParent to transfer that object to another scene and then try to release instance you get a KeyNotFoundException on line 722 of Addressables which is the s_sceneToInstances dictionary.

    Most likely it seems SetParent doesn't trigger any sort of update if it changes the scene. So using the scene as the key to remove the instance won't match.
     
  2. PaulBurslem

    PaulBurslem

    Unity Technologies

    Joined:
    Oct 7, 2016
    Posts:
    79
    Correct, there is no trigger to get notified that an instance changes scenes.

    Addressables API has this method that is intended to help with this situation:
    public static void RecordInstanceSceneChange(GameObject gameObject, Scene previousScene, Scene currentScene)

    Just call this method anytime you move an instance to another scene.
     
    Last edited: Aug 21, 2018