0 votes

I want to write a global state machine to change the state of the whole game. For example, start state for start menu and when player hit new game button then change to gameplay state and generate a new game.
Any idea or good practice how can I implement such a state machine in godot?
Thanks!

in Engine by (74 points)

1 Answer

0 votes
Best answer

Hi !

I'm really new to the godot engine but I think the scenes are already a FSM.
Each scene represents a state (scene menu, scene game) and you can go from one scene to an other (one state to an other) with get_tree().change_scene()

In your case in the menu screen just connect the new game button signal pressed to a method that will load the game scene.

If you really want a FSM just go with an autoload script (Singleton) keeping the current state of your game with a basic state pattern.

by (60 points)
selected by

Thanks, it's really helpful info!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.