So I have this scene with several images linked together (starport, main street, city entrance)
From the city entrance image I can go to the overworld map which is another scene.
I am able to switch scenes but it shows the first node (starport). Is it possible to link (with “get_tree().change_scene_to_file(”")) but to a specific node?
When you change scenes using change_scene_to_file, it removes your current scene and loads in the new scene. So however you scene loads up by itself, is how it will show. You cannot directly pass additional variables or instructions directly.
However, it is very common to need to load a scene in a particular state, in your case, showing city entrance (say). This is like loading a main_game scene but from a saved game, so it loads in a particular state, or loading a player scene where the player has pre-set abilities or health settings etc.
You can achieve this in a few ways. The way I would recommend is to create a global called something like 'SceneManager" and in it you can just have a variable called something like
overworld_map_startup_scene: String = "Starport"
Now in your entrance scene, you can set this variable to be, say, “City Entrance”, then change scene to the overworld map. In your overworld map, on loading, read the variable above, and show the appropriate scene using something like a match statement.
match SceneManager.overworld_map_startup_scene:
"Starport":
# whatever to load this part
"Main Street":
# whatever to load this part
"City Entrance":
# whatever to load this part
Now I kind of understand the logic but being way too much of a noob with godot (and coding in general) I am having a hard time putting your solution into the work
I will try to dig in that direction though.
you can use any loaded Godot’s Engine object too to make references without use of scene tree completely.
for instance Godot’s default singleton “IP” can be used in way:
IP.set_meta("object_reference", self)
and then accessed from another node from any place
IP.get_meta("object_reference")
this works for any data type
don’t forget to check using has_meta(name) and remove it if used for node tree_exiting.connect(func():IP.remove_meta("node_reference"))