C# - The process of creating a static class

Godot Version 4.2.1

Question

using Godot;

namespace Game.Data
{
    public static partial class ModeTracker
    {
        [Signal] public delegate void ModeChangedEventHandler();
        public enum Mode {None, Menu, Play, Pause, Selection};

        private static Mode currentMode = Mode.Menu;
    }
}

I want to create a class that contains the current game mode. I thought about creating a static class, but wondered at what point. I assume that when I try to call from another class, for example to bind the ModeChanged signal to the player, then this will definitely happen, because the static class will be created before the player class is created. I don’t quite understand how this works and I noticed that I can’t inherit from a class to get a static class. What do you think is best?

1. Create a non-static class and inherit from RefCounted and create a new instance when the game starts.

2. Create a static class like in the example above.

3. Create a non-static class and inherit from RefCounted and instead of creating an instance, add it to Autoload

If you are using Autoload then there is no need to instantiate a new version. The Autoload feature will do that for you.

Just create a class like normal and make all your ‘stuff’ in it (variables and methods) static.

Thats how I do my fake singletons.

You can of course create true singletons in c# and Godot will not know they exist, and that will still work. However I don’t know if that has implications for Garbage Collection or not.