+1 vote

Hi all,

I'm going through saving/loading my levels (docs: https://docs.godotengine.org/en/3.0/tutorials/io/saving_games.html?highlight=to_json) in a demo project

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

"Rows" and "Row1" / "Row2" 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

in Engine by (18 points)

1 Answer

+1 vote

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:

https://godotengine.org/qa/6491/read-&-write

by (661 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.