You're welcome, I'm glad it works (I was not totally sure it would if I'm being honest). I'll try to answer your other questions.
[...] I guess it has to be type _Data
because it just inherits from Node
and is therefore a "different" class, right?
Yup! Because _Data
extends Node
you cannot access any of the variables and functions without casting. This is all because of polymorphism! Here is an article that explains polymorphism (if you are curious).
As far as autoloads go, yes and no.
When you mark a script as a singleton/autoload in Godot through the editor, what it does is creates a node with your script attached that exists outside the scene tree. The biggest reason you want your node (with your script) outside of the scene tree is so when you change scenes the data is all still there.
In GDScript you still have to call get_node
, exactly the same as C#'s GetNode
. For example, in one of my games I use a singleton/autoload for holding all of the input and graphics options in the game. In GDScript, I call get_node("root/Global_singleton")
and that returns my global singleton node (I called my singleton/autoload 'Global_singleton' in this case. In your case it may be something different, so you'd need to change the name from 'Global_singleton' to the name you put in the editor).
In C# it should be (Global_singleton)GetNode("root/Global_singleton")
if singletons/autoloads work the same way as they do in GDScript.
All of that said, it is entirely possible to make a global data node without using a singleton/autoload structure. It would be a lot more work, but it is doable. I should also mention that if you do not plan to change scenes, then having the data the way you do currently will work fine, but when you change scenes the data will be reset to whatever the defaults are unless you find a way to store it across scenes (saving to a file would be one way).