Godot Version
v4.2.2
The situation
I want to make a main menu for my first project but I can’t figuer out how to chage the curent scene. I dont now the key whord that I need.
Here is a reference of my code:
extends Control
@onready var button = $Button
func _on_button_pressed():
print("click")
#load the next scene please =(
You could try using something like this.
var res=load(“res://scene”)
var scene=res.instance()
get_node(“/root/mainscenename”).add_child(scene)
Then when you are done with that scene,
scene.queue_free()
You should add error checking in it, but it works. This is how I handle my scenes.
1 Like
I thought I had it and it gave me a erro. It is not your falt, I probably didn’t understand
Here is my code
extends Control
@onready var button = $Button
func _on_button_pressed():
var res = load("res://scenes")
var scene = res.instance()
print("click")
get_node("root/level_1")
scene.queue_free
you can use get_tree().change_scene_to_file("res://your_scene_here.tscn")
1 Like