Save and Load feature for tile map

Godot Version


Hi there!

I’m currently working on a save system for my farming game for a jam. I’ve been able to save the position of scenes in a map by adding them alongside their locations into an array and then loading that each time the game loads the map.

The player can interact with tiles and edit their data by hoeing them similarly to stardew valley so I need to save each tile’s data.

I tried a similar approach using Tilemap.get_tile_data() and get_custom_tile_data() (the custom data determines what tile is to be displayed) and flinging the values alongside their position in an array.
I don’t have the exact code as I’m writing this on my phone but it went something like this.

var tile_locations =
var tile_data =
const map_size_x = 48
const map_size_y = 48
func load_data():
for x in map_size_x:
for y in map_size_y:
set_cell(layer_0, Vector2i(x,y), tile_data[x ])
func write_data():
Var current-tile = Tilemap.get-cell_data(x,y)
Var current-tile-data = Tilemap.get-custom-data(“terrain”)

Basically what I’m trying to do here is get the custom-data value for each tile, add that to an array, then on instantiation of the scene have each tile’s data drawn.

Thank you! Apologies for the code, my laptops not available right now so I can’t access the actual one.