godotengine / godot-docs

Godot Engine official documentation
https://docs.godotengine.org
Other
3.81k stars 3.09k forks source link

Singleton (Autoload) C# ButtonPressed Code does not work #9526

Open rzt3 opened 3 months ago

rzt3 commented 3 months ago

Your Godot version: 4.2.2

Issue description: The code below doesn't do anything.

// Add to 'Scene1.cs'.

private void OnButtonPressed()
{
    var global = GetNode<Global>("/root/Global");
    global.GotoScene("res://Scene2.tscn");
}
// Add to 'Scene2.cs'.

private void OnButtonPressed()
{
    var global = GetNode<Global>("/root/Global");
    global.GotoScene("res://Scene1.tscn");
}

Scene2.tscn and Scene1.tscn don't exist in the template provided. This also isn't how Godot's signals work in C#. (Refer to https://docs.godotengine.org/en/stable/tutorials/scripting/c_sharp/c_sharp_signals.html.)

Also, the user needs to create the C# scripts by themselves. (The C# files don't exist in the template)

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

raulsntos commented 3 months ago

The template singleton_autoload_starter.zip is a GDScript project, we don't provide a C# version.

File and directory names in C# code snippets use PascalCase since that's the recommended convention for C# projects. But the convention in GDScript projects is to use snake_case.