Beginner question - How can i load a scene to a specified node

Godot Version

4.5.1-stable

Question

I have a main-node “Game” and in there a subnode “Maps”.

Now i try to find a way during start of the game to load a scene “field-01” into the node “Maps” because this should be the main map-container.

i tried it on this way

extends Node
class_name MapManager

@onready var Maps = $"/root/Game/Maps"

func _ready() -> void:
	Maps.get_tree().change_scene_to_file("res://scenes/Fields/field_0.tscn")

but always the main-scene from the projact-settings will be load instead of mine.

can someone help me with a little hint?

Hi,

You can instantiate your scene like this:

var scene_instance = load('res://scenes/Fields/field_0.tscn').instantiate()

and then add it as a child node of Maps like this:

Maps.add_child(scene_instance)
1 Like

you are the greatest. many thanks - it works absolute fine

1 Like