Disable don’tdestroyonload object

Hello guys,
So I need help with something. In my home menu, I made a don’tdestroyonload object. I was wondering when I start playing my game in another scene, is it possible to disable the don’tdestroyonload object by calling it with findobjectwithtag, so that I don’t want it to appear in my game scene? If so, how do I do it please.

Why would you disable it when you have told it not to be destroyed (ie, keep it persistent over scenes?) Can you elaborate a bit more on this. It would be a better idea to keep a reference to it in another script and then manage it from there.

GameObject.SetActive(false);

can also Destroy() the gameobject, then it wont appear in new scene.

Get a reference to the object when the other scene loads (FindWithTag or whatever else), and Destroy it like usual.

Though, as it was already mentioned, it’s a bit unusual that you want to destroy an object that’s supposed to persist between scenes when a scene loads.

What does the object do? Does it even need to be marked as DontDestroyOnLoad?

Just make the GameObject a child of any other GameObject in the scene which you have not called DontDestroyOnLoad. It will then be destroyed on scene change, and you won’t have to destroy it manually. If you change your mind again, just make it not a child again.

DontDestroyOnLoad only works when the object is in the root of the scene.

6 Likes