Overview - DontDestroyOnLoad usage
What is it?
DontDestroyOnLoad is a Unity function that keeps a game object alive when switching between scenes. Normally, when you load a new scene, all objects in the previous scene are removed. Using DontDestroyOnLoad stops this from happening for specific objects. This helps keep important data or managers running continuously.
Why it matters
Without DontDestroyOnLoad, you would lose all objects and their data every time you change scenes. This means things like player stats, music players, or game managers would reset or disappear, breaking the game experience. DontDestroyOnLoad solves this by preserving objects, making games feel smooth and consistent.
Where it fits
Before learning DontDestroyOnLoad, you should understand Unity scenes and how objects are created and destroyed. After this, you can learn about singleton patterns and scene management to organize persistent objects better.