If you use an autoload or persistent node to manage all your scene changes, it'll make this process easy. Something like:
World
- Player
- current_scene
- house_2
The World node and the current_scene node will never change, they exist solely to carry the current scene the game is displaying, and to manage the scene transitions (done in World)
The way I'd do it is to have each door node have a unique name from every other door in your game, and have them all have a spawn point node as a child. Let's use an example of a town with three houses inside. Each of the doors that are in the town scene are called outerdoor1, outerdoor2, and outerdoor3. The door inside the first house is called innerdoor1, the one in the second house is called innerdoor2, and the third is innerdoor3. The player in currently in house_2, and walks up to the door to go to town. The house door sends a signal to the World node:
signal player_entered_door(scene, door_name)
#After the door has been triggered:
emit_signal("player_entered_door", name)
As long as World is connected to the signal, which you'll have to do on ready for each door, the door that's being triggered will tell the World node exactly which door the player is using to change the scene (by passing its own name).
World can take that name, and compare it to a dictionary of doors, to determine where to spawn the player. Here's a rough example:
var door_dict = {
"inner_door_1" = {
"destination" : #put the path to the town scene here ,
"exit_door" : "outer_door_1"
}
"outer_door_1" = {
"destination" : #put the path to the house_1 scene here ,
"exit_door" : "inner_door_1"
#Etc. Etc., fill in the rest of the door and town names here.
}
func on_player_entered_door(doorname):
#Transition the scene by first deloading the current_scene child
$current_scene.get_child(0).queue_free()
#Then loading your corresponding other scene.
var new_scene = doors_dict[doorname]["destination"]
load_scene(new_scene)
#And after the scene has loaded, move the player to the corresponding door spawn
$Player.position = $current_scene.get_child(doors_dict[doorname]["exit_door"]).position
There are better ways to organize your doors_dict
, like using sub-dictionaries corresponding to the individual scenes and passing those scene paths when changing scenes, but this demonstrates the basic idea.