Make signal change my scene from another scene

Godot Version

Hi guys

I am following tutorial https://www.youtube.com/watch?v=S8lMTwSRoRg&t=354s

It is about making game with button, but I want to make some variations about how the buttons being played using signal. In his tutorial, he use this code

Extends Node2D

func _ on_quit_pressed():
get_tree().quit()

func _on_play_pressed():
get_tree().change_scene_to_file(“res://world.tscn”)

And, this is his result
msedge_IhlmkYCESa

Meanwhile, this is my code

Extend Node2D

func _on_play_pressed():
$Play.hide()
if Input.is_action_pressed(“start_game”):
preload(“res://scenes/world.tscn”)

func _on_quit_pressed():
$Quit.hide()

Here is my result
Godot_v4.2.2-stable_win64_0LjsXQpSx3

Note :
I include InputMap

im not sure what you want to do but if you want to change the scene you have to call:

so this code would look like this:

if Input.is_action_pressed(“start_game”):
    get_tree().change_scene_to_file(“res://scenes/world.tscn”)
1 Like

I don’t quite understand what you want to accomplish with preload(“res://scenes/world.tscn”).
That’s a statement that practically say "preload the resource found under this path but dont save it to any variable and don’t do anything with it.

You usually find it outside of a function, for example like this
var world = preload(“res://scenes/world.tscn”)
which will turn the path into a resource that you can .instantiate()

@herrspaten’s solution is completely valid.

It is about making game with button, but I want to make some variations about how the buttons being played using signal.

Yan can do this before the scene is changed. What I believe is there is a play button and you want the play button to be pressed either by mouseclick or by a keyboard press (for example: Enter, Spacebar). You could maybe make use of InputEvents that checks on func _input() or inside func _process()

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.