- Home /
Why does my Player Object's Transform get destroyed when loading a new scene?
Feel like a newbie, 4 games in with Unity and counting... However,
I have a Player object, who's transform is tracked and used by a Camera Script. Both the Player GameObject and Camera gameobject in the hierarchy have a script with "DoNotDestroyOnLoad" used. This appears to work...
However, upon loading a new scene, both Player and Camera are still in existance, as expected, but the Camera script which references the public Transform of "Player" complains that the transform has been destroyed, but the script is still trying to reference it.
Looking at the Camera script in the inspector shows the "Player" transform is still set... but the camera doesn't actually track the player (it's transform) and ceases to work.
What am I missing here? I read that the objects using DoNotDestroyOnLoad are actually destroyed between scenes and then re-made at the loading of the new scene, in a pseudo-fashion of "not" being destroyed...
How can I keep this camera from losing the reference to the Player Object's transform through a scene load/change?
Thank-you for your input.
Continue the confusion: Unity Documentation for DoNotDestroyOnLoad says: " If the object is a component or game object then its entire transform hierarchy will not be destroyed either." So, I cannot wrap my $$anonymous$$d around why I am having this problem.
Your answer

Follow this Question
Related Questions
How to stop objects you picked up from reappearing when you go to another level and return 1 Answer
How to disable DontDestroyOnLoad on throwables? 0 Answers
Getting MissingReferenceException on Canvas text even though I used DontDestroyOnLoad 1 Answer
Can I add an exemption on DontDestroyOnLoad? 1 Answer
How do I transfer a gameobject created in one scene to another scene AND use it in a c# script? 1 Answer