0 votes

I have an "overworld" where the player can walk around and find dungeons/towns. When a player is overlapping one of these locations they have the option to enter them. Doing so causes them to switch scenes (to the dungeon scene where a different player scene is used, for example)

When the player exits the dungeon I want them to be able to return to the "overworld" with everything staying saved/the way it was before they entered the dungeon.

In the "playeroverworld.gd" script, I call the savescene() function from the Global.gd singleton.

func _input(event):
if event.is_action_pressed("space"):
    GLOBAL.save_scene()

this is my code for saving the overworld scene and entering a dungeon:

func save_scene():
var root = get_tree().get_root()
saved_scene = root.get_child(root.get_child_count() -1)
get_tree().get_root().remove_child(saved_scene)
var new_scene = temp_scene.instance()
get_tree().get_root().add_child(new_scene)
get_tree().set_current_scene(new_scene)

This method is in a singleton called "Global.gd"

The variable "saved_scene" is also in that script.

Whenever this method is run I get a list of errors that all say:
0:00:08:0751 - Condition ' !area_in && !E ' is true.

I assume this is somehow related to the fact that the player_overworld scene is an Area2D node that checks for overlapping areas every frame. I do not know how to get rid of these errors and I am wondering if there is a better way to do scene switching and returning. I just want to have an overworld scene that is persistent and can safely be switched.

asked 3 days ago in Engine by thewraithmod (34 points)

1 Answer

0 votes

I would save the data to a file instead of keeping it in memory. It might be a bit more work to set it up this way but its better in the long run. Check out the tutorial on saving and loading. http://docs.godotengine.org/en/3.0/tutorials/io/saving_games.html
Also I dont understand why you have a world as an area2D. What does your scene tree look like while you are in the overworld?

answered 3 days ago by happycamper (97 points)

My world is not an area2D (it's a Node2D). The player scene which i named "player_overworld" is an area2D node.

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.