godotengine / godotengine/godot-docs
Clarify documentation for C# autoloads
- Dominant language
- reStructuredText
- Stars
- 5.7k
- Forks
- 3.8k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 25
Description
**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:
>
> ```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()`:
>
> ```cs
> 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:
>
> ```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()`:
>
> ```cs
> 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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.