The autoload documentation seems to imply the only way to achieve a similar effect to a gdscript autoload is to create a static reference to the node instance.
What I need is a singleton, static class, or autoload who’s methods will be accessible on both godot-cpp C++ code and gdscript.
One Idea I had is to create a static reference to a single node instance (hence accessible from godot-cpp) and then make it uniquely named %, which I believe would make it globally accessible in gdscript. Not sure how I’d “auto instantiate the node” though, or ensure that there’s only 1 instance of it… I guess I’d just have to have some other node do that for me.
Im looking for other ideas or refinements for my own, for how to do this with godot-cpp.
You can create and register singletons in godot-cpp, though it won’t be in the scene tree. This can be done in the initialize gdextension types function.
You can also declare static methods within a class, though it won’t have any object tied to it, so you must only use static variables too. This must be done in the class’ _bind_methods function.