+1 vote

The game I’m making has scene transitions when you enter different areas. However, upon returning to a scene you’ve already been in, it reverts back to the way it was before runtime. If I just needed to store a few variables, I could keep them loaded in a singleton, but I plan to expand on the game quite a bit and it would be really nice to have a way to just save the entire scene. Is this feasible for large maps? If so, how could I do it? Thanks in advance :)

Godot version 3.0
in Engine by (67 points)

1 Answer

0 votes
Best answer

You can save a scene like this:

func save_scene():
    var file_path = "res://your_scene.tscn"
    var scene = PackedScene.new()
    scene.pack(root_node_of_your_scene)
    ResourceSaver.save(file_path,scene)

Note that when instancing or removing nodes from this scene, you have to set the owner or it won't get saved.

When instancing a new node:

$new_node.owner = root_node_of_your_scene

When removing a node:

$node_to_remove.owner = null

And make sure you don't override your original scene.

by (1,468 points)
selected by

How do you then load the packed scene?

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.