Pass a class instance from GDScript to c++ module class

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By misc

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

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.

hungrymonkey | 2018-05-09 23:19