In this article, Setsuna will walk you through a handy GDScript class that simplifies the process of switching scenes, reloading the current scene, and quitting the game.
SceneManager class
To streamline scene management in a Godot project, a custom GDScript class
named SceneManager
will be created. This class will utilize a dictionary
to store the paths to different scenes, making it easier to reference them with friendly aliases.
Setsuna is using Godot version 4.2-dev, but the concept is the same for various versions.
Here is he code:
1 | extends Node |
How to use
Initialization: First, configure the Autoload
feature in project settings
. This step ensures that the SceneManager class is accessible throughout out whole project.
In the example provided by Setsuna, an instance with the name “SM” of the SceneManager.gd
script is created.
Just call the function aloud, or with the nickname when the function needs one.
For example:
1 | func _on_quit_pressed(): |
That’s it. Really simple.
May you have a smoother game development,
and happy game-making with Godot 4.2!
Setsuna
12/10/23 Midnight