Advice? 2 states to save - Level Editor map and a game state

Discussion and help for Easy Save 3
Post Reply
bzwill
Posts: 7
Joined: Mon May 14, 2018 8:58 pm

Advice? 2 states to save - Level Editor map and a game state

Post by bzwill »

Hi There,

I have a unity game which has an in-game runtime level editor, which currently saves out levels to XML, this was written in C# using it's native XML serialisation. The approach saves each 'WorldObject' (the parent class for every individual gameObject) to a small container class, with only the values it needs, then at load time, turns those back into full objects by iterating a list, creating prefabs and returning them their customised values. This works great for what I needed a year and a half ago :) When designing it, even though some objects have 10 + MonoBehaviours on them, only one ever held data that was required to save an initial level state. All other components handled a small play state thing (like targeting).

Now I need to also support playstate serialisation so players can save their progress, and after hoping there would be a silver bullet, it looks like that's not the case, which is fine. I am wondering what the best approach is.

My current thinking is it should probably involve two stages of loading, one which invokes the same state as the level editor, ie it uses that load process, and restores all objects to their starting state. Then a second process that iterates over them and move them to their in-play state, and adds any play-time created objects such as projectiles, etc.

If it's any help, my current pattern for WOrld Objects look something like:

Gameobject
*WorldObject / saved for editor
- GridPosition
- Rotation
- UniqueFieldsToType
- AnObjectRefToSomething
- A patrol path
*Targeting
- a TargetableObject component on another WorldObject
*Vision
- a list of TargetableObjects in vision

At this stage I am looking for some high level solution architecture advice - I am new to having to write a saving system that perfectly preserves play-state, and with this added layer of complexity, I am just not sure where to start

- Help appreciated!

Please feel free to ask more questions, thanks for your help.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Advice? 2 states to save - Level Editor map and a game s

Post by Joel »

Hi there,

I recommend taking a look at the Saving & Loading GameObjects/Prefabs guide, as this seems to be what you're after.

Note that it will only save Components which are natively supported, or which have had support added in Assets > Easy Save 3 > Types.

Having two states as you've described is indeed the way to go. If you save them out to two separate files, this will also make things a bit easier to manage.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
bzwill
Posts: 7
Joined: Mon May 14, 2018 8:58 pm

Re: Advice? 2 states to save - Level Editor map and a game s

Post by bzwill »

Thanks for the quick reply Joel.

Off the top of your head should I also use both files to fully restore save game, or simply manage to different ways of saving and loading level?

I feels there's advantages to both approaches?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Advice? 2 states to save - Level Editor map and a game s

Post by Joel »

Generally I would do whatever is easier for you, and what produced cleaner and more understandable code.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply