Loading / Saving Game state, especially nodes that are not linked

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

Hi all,

I’m going through saving/loading my levels (docs: Saving games — Godot Engine (3.0) documentation in English) in a demo project

  * level.tscn
    - Rows (node2D)
      - Row_1 (node2D)
         * several links to bricks.tscn
      - Row_2 (node2D)
         * several links to bricks.tscn

“Rows” and “Row_1” / “Row_2” are used as container nodes for the “Bricks” objects, an so the resource file by “get_filename()” is empty.
The whole example in the docs bases on objects that are linked…

The whole thing in the docs is clear to 90%, but what do i do with objects that are not linked from an other resource file?
How do i instanciate them, or what information do i need to save to load them later

:bust_in_silhouette: Reply From: JulioYagami

This usually depends on the type of node. For example, on a Node2D you will want to save your position. Loading and saving is a complicated process to do, especially when you have many instances.

First you will need to store the data in variables, in case the position would look like this:

var pos = [Vector2(getTheInstancePosition.x,getTheInstancePosition.y)]

I made an array so you can save multiple positions (as you will want to do for so many instances). Once saved you will want to export them from your game and for this you can create a text file. See the link below: