Serializing Nested Classes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By nucky9

Hi,

I’m trying to develop a save system for saving my main map. The map is a 2d array of MapTile classes, where each MapTile has associated variables. Some of these variables include references to other classes, like a Settlement class, which in turn stores its own variables.

Using dictionaries, and serializing to json seems to be the preferred way of saving state to file in Godot, but I’m not sure how I would go about doing so without packing/unpacking each layer of each tile of the 2d array manually, which seems like a bit of a pain.

Is there a more convenient way to do this?

Thanks!

Is there any way you can make scenes out of them?

Ertain | 2018-10-28 23:14

I guess probably? I could make a MapTile scene, with a child settlement node. However, 2400 of these MapTile scenes would need to be instantiated. I don’t know if there would be a performance hit? Also, accessing the data from MapTiles, and their child nodes, would be a lot less convenient through the scene tree, then directly through the 2D array.

nucky9 | 2018-10-29 02:31