godotengine / godotengine/godot-cpp
Support for Custom Servers/Auto-Load Singletons
- Dominant language
- C++
- Stars
- 2.7k
- Forks
- 809
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 8
Description
### Godot version
4.1.1stable
### godot-cpp version
4.1.1stable
### System information
Arch, btw
### Issue description
I am trying to add a new Server to act as a something like an AutoLoad Singleton (a global resource that maintains state across the lifetime of the game application, and is given work by Nodes) in GDExtension. I run into the following issue however:
`extension/src/register_types.cpp:37:34: error: 'class godot::Engine' has no member named 'add_singleton'; did you mean 'get_singleton'?
37 | Engine::get_singleton()->add_singleton(Engine::Singleton("SteamAudioServer", SteamAudioServer::get_singleton()));
| ^~~~~~~~~~~~~
| get_singleton
extension/src/register_types.cpp:37:56: error: 'Singleton' is not a member of 'godot::Engine'
37 | Engine::get_singleton()->add_singleton(Engine::Singleton("SteamAudioServer", SteamAudioServer::get_singleton()));
`
It seems the add_singleton method is not exposed by GDExtension for the Engine singleton. A version of this code works fine with old-fashioned Modules, however. For this implementation the Server (or Singleton) needs to load before nodes in the load order. Any suggestions would be great.
### Steps to reproduce
Try to adapt a Custom Server module to GDExtension:
https://docs.godotengine.org/en/stable/contributing/development/core_and_modules/custom_godot_servers.html
### Minimal reproduction project
N/A
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.