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

I'm trying out a sample c++ module. How can I pass an instance from GDScript to c++ module class? In the sample below, showNumber() uses the default returned value of A.getNumber() instead the returned value of SubA.getNumber().


#ifndef SAMPLE_H
#define SAMPLE_H

#include "reference.h"

class A : public Reference
    GDCLASS(A, Reference);

    static void _bind_methods();

    virtual int getNumber();

class B : public Reference
    GDCLASS(B, Reference);

    static void _bind_methods();

    int showA(Ref<A> a);



#include "sample.h"
#include "variant.h"

// A
int A::getNumber() 
    return 100;

void A::_bind_methods()
    // ClassDB::bind_method(D_METHOD("getNumber"), &A::getNumber);
    BIND_VMETHOD(MethodInfo(Variant::INT, "getNumber"));

// B
int B::showA(Ref<A> a)
    return a->getNumber();

void B::_bind_methods()
    ClassDB::bind_method(D_METHOD("showA", "a"), &B::showA);


extends Node

class SubA extends A:
    func getNumber():
        return 50

func _ready():
    var sub =
    print("SubA: %d" % sub.getNumber())

    var b =
    print("SubA passed to B: %d" % b.showA(sub))


OpenGL ES 3.0 Renderer: Mesa DRI Intel(R) Sandybridge Desktop 
SubA: 50
SubA passed to B: 100
in Engine by (12 points)

I would first start asking then irc then I would recommend

reporting it to the issue page.

at least report it to godot-docs

they would probably tell you what is wrong faster

I am looking at the bind_method code and it does nothing when tools are disabled.

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.