godot-docs icon indicating copy to clipboard operation
godot-docs copied to clipboard

Clarify documentation for C# autoloads

Open sockeye-d opened this issue 4 weeks ago • 1 comments

Your Godot version:

4.6.dev3

Issue description:

The documentation for autoloads in C# reads quite badly:

If the Enable column is checked (which is the default), then the singleton can be accessed directly in GDScript:

PlayerVariables.health -= 10

The Enable column has no effect in C# code. However, if the singleton is a C# script, a similar effect can be achieved by including a static property called Instance and assigning it in _Ready():

public partial class PlayerVariables : Node
{
    public static PlayerVariables Instance { get; private set; }

    public int Health { get; set; }

    public override void _Ready()
    {
        Instance = this;
    }
}

The enable toggle has nothing to do with accessing the instance in C# in a type-safe manner.

I think this should be something more like this:

If the Enable column is checked (which is the default), then the singleton can be accessed directly in GDScript:

PlayerVariables.health -= 10

The Enable column has no effect in C# code. Unlike GDScript, C# doesn't have a built-in way to get autoloaded nodes by name, but a similar effect can be achieved by including a static property called Instance and assigning it in _Ready():

public partial class PlayerVariables : Node
{
    public static PlayerVariables Instance { get; private set; }

    public int Health { get; set; }

    public override void _Ready()
    {
        Instance = this;
    }
}

URL to the documentation page:

https://docs.godotengine.org/en/latest/tutorials/scripting/singletons_autoload.html

sockeye-d avatar Nov 17 '25 02:11 sockeye-d