Page 1 of 1

How Can I save singleton classes?

Posted: Tue Apr 20, 2021 9:28 am
by Uchiha I_T_H_
I have an Interface called IGameState and have 2 derived Classes from it.(and are singletons)
I also have a field of type IGameState called CurrentGameState.
I have already created the Custom es3 type file
code link is given below.

https://hatebin.com/pmaqzahtcj

es3Type code

https://pastebin.com/UB1qE6r8

I use singletons and statics heavily. What I want is a robust save system which saves everything when the game crashes. So when I fix-up the bug I can jump into the moment where the crash occurred..
This will reduce the development time as I don't have to play the game from the start to reach the point where the bug occurred.

Re: How Can I save singleton classes?

Posted: Tue Apr 20, 2021 10:06 am
by Joel
Hi there,

I don't appear to be able to see anywhere in your code where you're saving or loading.

Also as there are no serialisable fields in your LegendaryState or AmetuerState classes, just a property with only a get method (which is not serializable), nothing will be saved.

All the best,
Joel

Re: How Can I save singleton classes?

Posted: Tue Apr 20, 2021 11:08 am
by Uchiha I_T_H_
Oh sorry check this code

https://hatebin.com/crnqnhwwat

I am using autosave feature so as It gets initialized in Awake() so I am just doing a null check.
also, yes there are no field, all I want to save is the reference of the instance.
I have tested that references can also be saved using odin serializer.
If the current system can't serialize then can i inject odin serializer into picture. if so then how?

Re: How Can I save singleton classes?

Posted: Tue Apr 20, 2021 11:42 am
by Joel
Hi there,

Easy Save will only store references to UnityEngine.Object fields types (same as the Unity Editor). If you want to store non-Unity reference types you would need to create your own way of referencing it. For example, adding a field to your class which assigns a unique ID to it, and then saving this unique ID. Then when you load, load this unique ID and use it to find the instance of your class with that ID.

All the best,
Joel