Search Unity

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

DontDestroyOnLoad doesn't preserve state, disabled object is being re-enabled on scene load

Discussion in 'Editor & General Support' started by DreamPower, Sep 4, 2019.

  1. DreamPower


    Apr 2, 2017
    I was stupid, my Action function was getting triggered an extra time because it wasn't getting unsubscribed, and that was reactivating my object. Nothing to see here, move along!

    I thought DontDestroyOnLoad just kept objects exactly as they were when a new scene was loaded. But I'm not experiencing that: my object has activeSelf false, then I load a different scene that does not include the object, and the object's OnEnable function is called and the object is made active again. I tried to re-disable it with SceneManager.sceneLoaded, but the enabling is being done after sceneLoaded .

    How can I prevent my disabled object from being enabled, and OnEnable called? Is this intended Unity functionality?

    Unity 2019.2.3
    Last edited: Sep 4, 2019