If Parent gameobject has DontDestroyOnLoad does it apply to its children?
If I have an empty gameobject and its marked as DontDestoryOnLoad. Now if I add child gameobjects to this empty parent dynamically in code as I instantiate the children, then are the children also marked to be DontDestoryOnLoad? Or they have to be marked seperately via their own code?
Answer by Munchy2007 · Jan 13, 2016 at 08:18 PM
It covers all children of the object, regardless of when added.
If you un-parent a child that hasn't got it's own seperate dontdestroyonload script then that child will get destroyed on a scene change.
Thanks for the explanation. I just found this out by actually implementing it. One more thing, does it also not destroy the components of the children? Say the child has a script that does not have the check, for example`public static ChildClass instance; void Awake() { if(instance == null) { instance = this;} else { Destroy(gameObject) }` If the component script on child does not check this, then this script will be destroyed and reloaded right? Even if the child itself is not loaded?
Anything parented to a GameObject that is set to dontdestroyonload will be preserved, that includes all children and any components(scripts) they contain.
Your answer
![](https://koobas.hobune.stream/wayback/20220612060113im_/https://answers.unity.com/themes/thub/images/avi.jpg)