DontDestroyOnLoad object not serializable?

Hello there,

I am working on a project that use a DontDestroyOnLoad object (with singleton pattern) in order to switch information between scene. This works perfectly fine, but I have another problem. I’m trying to save my game so the player can continue it later on. The fact is, this DontDestroyOnLoad is my GameManager where some importants infos are stored (player position, rotation and others). in order to use a checkpoint system. So I’d like to serialize this object, but it seems it’s not working.

Do you have any idea on how I could achieve such thing? Maybe I should store these information in another gameObject?

Thanks for your future help!

You cant serialize a class that inherit from MonoBehaviour in the way you are describing. I suggest you create a simple intermediate class just for storing the data and then copy what you need into and out of it as you do the saving and loading. Take a look at our JSON class here Unity - Manual: JSON Serialization