How to save a generated 2D array to disk in editor?

Godot Version

4.0

Question

Hello,
I am generating a 2 dimensional array full of “tile” dictionaries. Simplified, the code looks something like this:

	var tile_map = []
	for x in range(x_array_size):
		var x_array = []
		for y in range(y_array_size):
			var tile = {}
			x_array.append(tile)
		tile_map.append(x_array)

My issue is that the arrays I am generating have very large sizes, I am using them for some procedural generation math. The code becomes very slow when the arrays are larger. I wanted to know if there is a way that I could generate the array a single time in the editor and save it to the games files (or the “disk”) so that I won’t have to generate every time I test or run my game. I have messed around a bit with custom resources and @tool, but is that the best way to go about this?

Resources sound like a great way to do this, especially if you are pre-computing for the finished game rather than making something like save files to each user can generate their own tile_map to be saved.

If you do want to save to a file you can use FileAccess

2 Likes

Thank you!