Fix the most common issue that crop up in Unity!
InvalidOperationException: The following game object is invoking the DontDestroyOnLoad method: {script}. Notice that DontDestroyOnLoad can only be used in play mode and, as such, cannot be part of an editor script.
This error is slightly misleading. It can occur on non-editor scripts and it doesn’t mean there’s not a solution.
Use Application.isPlaying to check if the application is running before calling DontDestroyOnLoad.