GlobalClass for finiteStateMachine in c#

Godot 4.2

I’m making a 2d side scrolling game and wanted to add a state machine into the game. So I started watching tutorials, but they were all gdscipt (I use c#) and I kept seeing people turning the script into custom nodes and figured out that in c# I can do the same thing by using GlobalClass. now here are my questions, is the only way to do this using GlobalClasses? If not, how could I do it? Is it bad to make too many GlobalClasses? Because I remember learning that too many global variables make the program slower so I was wondering if it is the same with these GlobalClass custom nodes. Is the most effective way to make a state machine for my case a node based finite state machine?

I appreciate any feedback and response, also let me know if any clarification is needed, thank you!

The primary purpose of the [GlobalClass] attribute is to allow you to access classes marked with it as nodes through the editor. It is not essential to creating state machines. It can be useful if you want to conveniently reuse your state machine class across different scenes.

The [GlobalClass] attribute simply indicates to Godot that you want to access the class through the editor. It doesn’t affect performance if the class isn’t instantiated. What you might be referring to are singletons, not Global Classes.

3 Likes