- Home /
DontDestroyOnLoad on disabled object doesn't work?
Hello, I have some object that I want them to never be destroy so even when I switch scenes, they are not destroy. But sometimes, I need to be disable. But when I change scene, they just destroy because the script attached to them telling them to DontDestroyOnLoad is also disable.
Is there a better way to simply but them as a child in a parent and not disable the parent and put him or DontDestroyOnLoad? Or could I create a script on a GameMaster object that would tell other object to DontDestroyOnLoad even if they are disabled? What would be the most efficent way?
Thanks a lot!
I'm trying to figure this same issue out.. my current best guess is that you can have a script that runs on scene load that finds the object and enables it/disables it accordingly.
It's easy enough to get the object to disable itself in the Awake function if a condition is met (such as being in a scene where you want it disabled.. maybe it's a camera and you don't want to reuse it). $$anonymous$$aybe it would be best to have a parent object that is never disabled and simply controls and disables child objects, that way you always have something at a higher level that can control it and isn't disabled.
I'm actually going to try implementing this method now.
Answer by Eldamir88 · Sep 18, 2020 at 04:31 AM
Is there a better way to simply but them as a child in a parent and not disable the parent and put him or DontDestroyOnLoad?
Thay is exactly what I would do in your situation :)