This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Question #1
When instancing scenes from a c++ native script, what is the lifetime of the object returned by the pointer?

auto loader = godot::ResourceLoader::get_singleton();
godot::Ref<godot::PackedScene> myScene =
    loader->load("res://assets/MyScene.tscn", "PackedScene");
if (myScene.is_valid()) {
            Node* node = myScene->instance();
            //Do i have to "delete node;" in my C++ NativeScript class destructor?
            //Should I free it with Node::queue_free()?

Question #2
Lets say I have a C++ NativeScript class something like:

class MyClass : public godot::Sprite {
    GODOT_CLASS(MyClass, godot::Sprite);

    static void _register_methods();
    void _init();
    void _ready();
    void _process(float delta);

I want MyClass objects to be able to receive signals. As an example, lets say I want to receive the CollisionObject2D's signal for input event which has the following "signature" in the Godot editor:

input_event(Node viewport, InputEvent event, int shape_idx)

To do so I need to add a function to MyClass (and register it), but what should the signature for MyClass::handle_input_event be?

void handle_input_event(???)
void handle_input_event(Node* n, InputEvent* ev, int s_idx)?
void handle_input_event(Node& n, InputEvent& ev, int s_idx)?
void handle_input_event(Variant& n, Variant& ev, int s_idx)?

Is there a standard conversion for signal signatures to c++ types?

in Engine by (15 points)

Please log in or register to answer this question.

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.