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 = SubA.new()
    print("SubA: %d" % sub.getNumber())

    var b = B.new()
    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
asked May 7, 2018 in Engine by misc (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 How to use this Q&A? before posting your first questions.