DontDestroyOnLoad not working after changing parent temporary
Hey I have a specific problem with the DontDestroyOnLoad function for my object. In my project i have level loader and the player object can change scenes without getting destroyed. In one level a have an elevator and the player becomes the children object of the elevator while its inside of it
( the working elevator function: private void OnTriggerEnter2D(Collider2D collision) { if(collision.tag=="Player") { inSwitchArea = true; Debug.Log("in Area"); collision.transform.parent = transform; collision.gameObject.layer = 8; } } private void OnTriggerExit2D(Collider2D collision) { if (collision.tag == "Player") { inSwitchArea = false; Debug.Log("not in Area"); collision.transform.parent = null; collision.gameObject.layer = 9; } }
) After leaving the elevator, its not the children of it anymore, but now the DontDestroyOnLoad(gameObject) isnt working anymore while changing the scene.
I think the parent (elevator) is changing something in the child object (player), but I am not sure what it is and how to fix this. Maybe you have some backround knowledge.
bg, Alex
Your answer
Follow this Question
Related Questions
Scene stores variables after scene reload 0 Answers
multiple of same objects from DontDesroyOnLoad 0 Answers
How to keep selected player active and all others inactive when new scene loaded 3 Answers
How do I fix my animations after duplicating my character? 0 Answers
Destroyed object in DontDestroyOnLoad does not recreate in its main scene 0 Answers