How do I setup scene selection ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Wekita

I’m new to GoDOT and brand new to programming. I’m trying to create a title screen at the start of the game where all I have to do is select 1-9 to open scenes. “Space bar” to return to title screen and “esc” to end. I’ve searched through YouTube and web but can’t find anything like I’m looking for. The scenes are going to be 3D based. Can anyone help ?


:bust_in_silhouette: Reply From: Constannnnnt

For selection, you can basically create a menu and add buttons. Then, when a button is clicked, emit a signal to switch to the corresponding scene. Check the video for menu creation:

To load and change scenes, check the previous question: How to load and change scenes - Archive - Godot Forum

Scene Switching

What you’re looking for is in the Docs @ Using SceneTree — Godot Engine (latest) documentation in English

An example:


     ┖╴(Title Stuff) Node Script:

extends Spatial 
onready var current_scene = get_node("Title")

func goto_scene(path):
	call_deferred("_deferred_scene", path)

func _deferred_scene(path):
    # It is now safe to remove the current scene

	# Load the new scene.
	var new_scene = ResourceLoader.load(path)

	# Instance the new scene.
	current_scene = new_scene.instance()

	# Add it to the active scene, as child of root.

	# Make it compatible with the SceneTree.change_scene() API.

func _input(event):
    #Action keys set in Project > Project Settings > Input Map
	if Input.is_action_just_pressed("keyOne"):
	if Input.is_action_just_pressed("KeyTwo"):
	if Input.is_action_just_pressed("ui_accept"):
	if Input.is_action_just_pressed("ui_cancel"):

Wakatta | 2020-07-23 07:42

To load and change scenes, check the previous question: How to load and change scenes - Archive - Godot Forum

Sorry, Not what I was Looking for. I went through a few of those but wasn’t what I needed.
However, after posting this, I rummaged through some different types of tutorials and pieced together this:

extends Spatial

func _ready():

func _physics_process(_delta):
    if Input.is_action_pressed("ui_one"):
    if Input.is_action_pressed("ui_two"):
    if Input.is_action_pressed("ui_three"):
    if Input.is_action_pressed("ui_four"):
    if Input.is_action_pressed("ui_home"):

func _unhandled_input(event):
    if event.is_action_pressed("ui_quit"):

This works great, however I get caution’s that says “The function ‘change_scene()’ returns a value, but this value is never used.”

It doesn’t seem to interfere however, I don’t know what this means or what to change to get rid of the errors. Any Ideas how to make this better?

Wekita | 2020-07-23 23:43

As far as the Documentation goes, I don’t know enough about programming to understand it. I wish I did. Unless it’s all written out for me to study, I can’t interpret it.
(My brains wired weird like that.)
Some stuff I can understand in the doc’s, but other stuff I can’t.

Wekita | 2020-07-23 23:58

It is a warning, not an error. Check the doc: SceneTree — Godot Engine (stable) documentation in English.
You don’t have to worry about it and just leave it there. If you do, you can try

var e = get_tree().change_scene("res://start.tscn")
if (e):
      print("change scene successfully")
      print("failed changing scene")

Constannnnnt | 2020-07-27 22:29

Yeah i know what you mean.

In school i never understood tectonic plates no matter who or how it was taught. That being said if you don’t understand something skip it and try again at a later date when your knowledge is up to par.

Wakatta | 2021-04-12 21:11