How Can I save singleton classes?

Discussion and help for Easy Save 3
Post Reply
Uchiha I_T_H_
Posts: 20
Joined: Tue Apr 20, 2021 4:34 am

How Can I save singleton classes?

Post 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.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: How Can I save singleton classes?

Post 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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Uchiha I_T_H_
Posts: 20
Joined: Tue Apr 20, 2021 4:34 am

Re: How Can I save singleton classes?

Post 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?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: How Can I save singleton classes?

Post 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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply