Saving and loading map

Godot Version

4.6

Question

I’ve been working on making a text adventure game lately, and I decided that I wanted to make a map creation tool to help with managing the room layouts (and also to generate a visual map for the player.) I have it all working, but I’ve been having a ton of issues trying to actually save the map.

The map is an array containing nulls for empty cells and Sprite2Ds for the rooms. The Sprites have a Room resource loaded on them with the relevant room data.

Is there a way to save the array, maintaining the same Sprite2Ds with their correct resource files?

JSON.stringify(yourArray)

When I tried saving and loading via a Json file, even using Store_Var with keep objects, it would load the Sprite2Ds but their resources would be empty.

You’re not supposed to save an entire Sprite2D object / node as is, you’re supposed to save it’s properties that you care about, such as the location of it’s current texture (so you can load it back up when needed).

I recommend creating a save() and load() function respectively for all the objects you want to be able to save and load.

The save functin should return a dictionary with all the properties you care about, and the load function should accept that same dictionary back, and set them.

Then you can either put all your “loadable” objects in the same group, and iterate over them.