Parenting to DontDestroyOnLoad

Hey, All!

Is it possible to parent to DontDestroyOnLoad?

During the game the player can parent itself to a gameObject in the scene that isn’t DDOL. The player holds onto the DDOL script, but isn’t in the DDOL hierarchy anymore. I want my player back in the DDOL hierarchy. I attempted to save the old transform prior to parenting so I could re-parent to that old transform, but that isn’t working. SetParent(null) also just parents to the current scene.

Any recommendations?

Call DontDestroyOnLoad again instead of using SetParent. Your DDOL script presumably has DontDestroyOnLoad inside its Start() function - which is called once, and is undone by parenting it to another object.

2 Likes