Replies: 2 comments 4 replies
-
|
Hi! You're right, I haven't gotten around to adding an example that shows how to use the SaveState system. Here's a summery of how to use it: The current state of the world is stored in a class called WorldState. In a game manager script: The actual state to load/save consists of StateObjects containing StateWrapper objects. Example code to use in the Create method of a chunk: When the state of a door changes, change the Value of the door's StateWrapper state. When the StateObject is created, it automatically fills the StateWrappers with the relevant data from the WorldState if it exists. When a chunk is destroyed, it calls Unload on all StateObjects added to the states property of the chunk. This ensures the data from the StateWrappers is saved in the WorldState. WorldState.Save() also saves the state of all StateObjects to the WorldState before the WorldState is saved to disk, and WorldState.Load() sets the state of all StateObjects after loading it from disk. Generally the syncing of data is taken care of automatically. Apart from bools, the other supported data types are currently int, Point and Point3. I hope this can get you started. You'll probably have to look at the APIs of the mentioned classes to figure out more details. Let me know if anything is still unclear. Oh, and I'd be curious to hear about your project! Perhaps you could write a few words about it over in the Present your project category? |
Beta Was this translation helpful? Give feedback.
-
|
Ah, so it is as I feared. Seems quite fiddly/tricky to use with arbitrary objects, though it would work well for static-sized simple data like terrain heights. I'd prefer to just write my own serialization functions for objects, and have this library call those functions when a chunk has to load/unload. I guess I'd put that in the Create function of the chunk, and just load/unload based on whether destroy is true, and... hook into the WorldState's load/save callback to actually load or save my custom stuff? I'll write up a bit about my project, though it's really only a fledgling thing I'm largely doing for fun. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm struggling to figure out how to use StateObjects to save generated chunk data, and the samples don't seem to do anything with saving/loading. Is that correct, or am I missing something? (I'm using Sythelux' Godot version, but did check the code for the samples in this repo, too)
Beta Was this translation helpful? Give feedback.
All reactions