+1 vote

I am writing a c++ plugin and have a singleton setup. What I would like is some method in my plugin to be called to once the engine is setup and running such that all its features a ready to use. I want to connect to a website using https so cannot do this in the register_types callback.

Is there anyway to be notified in C++ of certain events that occur in the engine?

in Engine by (52 points)

I don't know of the proper way of doing singletons in Godot C++, but one way would be to make your class a Node (so you can make multiple of them, if possible?) that you can then put in AutoLoad. Then you'll be able to use the NOTIFICATION_READY notification (same as _ready in script)

1 Answer

0 votes

If you want to bind a class to gdscript with a singleton set up, you have to bind a dummy class. The dummy class access the singeton. The process of setting up a signal should be similar to a regular function call.

Size2 _OS::get_screen_size(int p_screen) const {
return OS::get_singleton()->get_screen_size(p_screen);
void _OS::_bind_method() {
ClassDB::bind_method(D_METHOD("get_screen_size", "screen"), &_OS::get_screen_size, DEFVAL(-1));



i would recommend using OS class as a guide.

Basically, you have a regular class

    void register_types() {
        foo = memnew(FOO);
         _foo = memnew(_FOO);

I am thinking of writing a guide on how to do these things but it will take awhile since Godot servers is an integral part of the engine,

by (427 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.