- Home /
Game Object Looses Children When Return to Scene
I have a game object with the Do Not Destroy on load but when I return to my main scene it looses some of it's children like the UI Slider, how do I fix that?
Bump. I still do not know why my prefab looses some of it's child objects when I return to it's original scene? And yes it does have a "DoNoDestroy" on it.
when you say 'children' do you mean children of the 'init' object, or just 'objects that init references?'
could you post a screen shot of your hierarchy before and after it breaks, ins$$anonymous$$d of just after?
I would say objects it references like the UI slider is on a panel on a canvas but it seems to loose connection to that when I change scenes and then return the slider no longer works?
Well if the other objects are not also marked as 'do not destroy' then they will certainly be destroyed (even if you later recreate them). Could that be what is happening?
Do not destroy guaruntees an object and all its descendants will not be destroyed, but does nothing to protect objects it references.
Answer by Firedan1176 · Dec 22, 2015 at 07:57 PM
Those are serialized properties, and those are not saved during scene changes when in Play Mode. DontDestroyOnLoad()
is intended for when you switch scenes, to keep those GameObjects in the scene.
So how would I fix my problem? What would I need to do in order to have my UI slider update when I return to my main scene. No one seems to explain properly how to do this.
Your answer
Follow this Question
Related Questions
Change gameObjects parent at runtime 3 Answers
How do I carry over ui text to the next by obtaining the gameobject children 0 Answers
Grid Layout Group leaking outside canvas. 1 Answer
using DrawMesh to draw all sub meshes and materials for a game object and children 1 Answer
How to run a function in a GO that have DontDestroyOnLoad 1 Answer