0 votes

I'm likely doing something wrong - but I don't recall having this issue previously.

My game does a procedural generation of a universe. All the space sectors which are scenes are generated in a world creation scene. The space sector objects are put in a list of objects.

Once the world creation is done... I change scenes to the 'main play' scene.

But all the objects are wiped out. The autoload list contains nothing.

Godot version 3.4
in Engine by (133 points)

After reading this documentation - seems to me, what I am doing cannot possibly work as the engine seems to want to kill all the child objects that were created on a scene.

I guess autoload/singletons are only good for maintaining simple variables, and not instanced objects.

Not sure how someone should go about moving all the objects on one scene - into another scene.

2 Answers

0 votes

Resetting the scene queues free every object of the old scene. This means any list You keep will contain empty RID after reset. Instead of a list of Objects You should keep a list of dictionaries of components, that are used to create these objects. For example :

var universe = [{"source" : "res://planets/sun.tscn","size":10,"color":ColorN("red")},"position" : Vector2(10,50),.....]

and when You reset a scene You can iterate through it :

for entry in universe:
      var inst = load(entry["source"]).instance()
      inst.size = entry["size"]
      inst.global_position = entry["position"]
      add_child(inst)

and so on

by (8,099 points)

Generally resetting the scene is primitive and problematic option of changing a level. It might be better to keep high scope node above your level, that will manage changing of scenes without resetting it. This way You can release low scope level and keep permament objects in high scope menager.

0 votes

In Godot Docs see:
Input and Output (I/O) » Saving games; and Scripting » Singletons (AutoLoad) - search for call_deferred.

You need to save the scene before delete it.

by (232 points)
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 Frequently asked questions and 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 [email protected] with your username.