- Home /
Should I use DontDestroyOnLoad or prefab for player
I am making a 2D Platformer game (my first game). At the end of each level, a "Level Complete" screen appears, where the user can press a button to go to the next level. I use different scenes for each level. My question is, should I use DontDestroyOnLoad for the player when changing scenes or should I have a prefab for the player and a different player object in each scene?
Answer by Strixie13 · Aug 06, 2018 at 09:10 PM
Definitely create a prefab of the character. You will almost certainly need it at some point.
For example, switching with DontDestroyOnLoad might work when the player is starting on level 1, but what if they saved and started up the game on level 3? In that case you would want to instantiate a new player, but then maybe use DontDestroyOnLoad as they progress through levels.
Thank you for your answer! So, If I create a prefab for the player and use it in each level, is there a reason why I would want to use DontDestroyOnLoad as they progress through levels?
Think of the context of a scene and a prefab. A scene holds static (unchanging) information. When you introduce a player, things will now change in the scene based on that players interaction. DontDestroyOnLoad helps you transfer information from one scene to another. For example a character gains 50xp on level 1 and acquires a new sword. DontDestroyOnLoad is an easy way to transfer that character into level 2 with the stuff they just acquired.
If you were to instantiate a new prefab each level, you are starting with a basic character model and have to find another way to add in the stuff they got from the last scene.