Maintaining DontDestroyOnLoad method after object becomes a child to another object.

Hi, in the game I am trying to make there is a level with moving platforms that make the player object a child for the duration of the collision.

private void OnCollisionEnter2D(Collision2D collision)
    {
        collision.transform.SetParent(transform);
    }

    private void OnCollisionExit2D(Collision2D collision)
    {
        collision.transform.SetParent(null);
    }

Player does have a DontDestroyOnLoad method so he can move between the levels freely. However that method disappears whenever i come into contact with one of the moving platforms so the game crashes while going to the next level because the camera is using the player object to follow him and without player is missing a reference. I am pretty sure that the cause is that it becomes a child object of the platform and the platform itself does not use that method. Is there a way to keep the DontDestroyOnLoad method no matter the circumstances fn the player object?

Why dont you just reload the player in for each new scene? If you have stats and such, just use PlayerPrefs or some sort of save/load system to pull those back into the new scene. Basically, Im asking why do you need to use DontDestroyOnLoad for the player?

Ya… this… you should reload your player each scene and one easy way to do that is with additive scenes.

Keep all the persistent state ABOUT your player somewhere else.

Additive scene loading is one possible solution:

https://discussions.unity.com/t/820920/2
https://discussions.unity.com/t/820920/4

https://discussions.unity.com/t/824447/2

A multi-scene loader thingy:

My typical Scene Loader:

Other notes on additive scene loading:

https://discussions.unity.com/t/805654/2

Timing of scene loading:

https://discussions.unity.com/t/813922/2

Also, if something exists only in one scene, DO NOT MAKE A PREFAB out of it. It’s a waste of time and needlessly splits your work between two files, the prefab and the scene, leading to many possible errors and edge cases.

Two similar examples of checking if everything is ready to go:

https://discussions.unity.com/t/840487/10

https://discussions.unity.com/t/851480/4

I have no idea why i did not think of that since it is the easiest thing to do. Thank you for your answers.