Skip to content

Singletons (Autoload) page seems to be wrong for C# #6981

@BigZaphod

Description

@BigZaphod

Your Godot version:
v4.0.stable.mono.official [92bee43ad]

Issue description:
I've been assured by my own attempts (and by folks on Discord) that accessing a GDScript Autoload from C# doesn't work quite the way the C# samples on the Autoload page seem to suggest for Godot 4 because the "Global Variable" checkbox in Godot doesn't apparently apply to C#.

I don't know if it worked this way in Godot 3.x or not, though, so it's possible the real issue is incomplete C# support in Godot 4?

For example, this C# sample shown on the page:

var playerVariables = GetNode<PlayerVariables>("/root/PlayerVariables");
playerVariables.Health -= 10; // Instance field.

That code seems to suggest that a type named PlayerVariables should exist in my C# code that was presumably autogenerated by Godot. The screenshot above this example clearly shows "PlayerVariables" is an autoload of a GDScript, but that doesn't seem to make any names exist over on the C# side. As far as I can tell, named classes in GDScript don't show up as types in C# so using GetNode<PlayerVariables>() can't possibly work. It'd be super handy if they did (and maybe they did in 3.X?) but they don't at the moment, anyway, as far as I can tell. Unless I'm doing something wrong.

The next C# sample also seems impossible for those same reasons:

// Static members can be accessed by using the class name.
PlayerVariables.Health -= 10;

I have no idea at this point if this documentation is just totally wrong and made up of wishful thinking, or if it used to work and now doesn't! I do wish it worked, though, and if it's supposed to work, I'd love to know what the heck I'm doing wrong. 😛

URL to the documentation page:
https://docs.godotengine.org/en/latest/tutorials/scripting/singletons_autoload.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:manualIssues and PRs related to the Manual/Tutorials section of the documentationbug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions