Skip to content

Objects instanced in c++ can't be bound to typed gdscript variables #430

@norton-corbett

Description

@norton-corbett

GDNative:

class MyCustomType : public godot::Node
{
    GODOT_CLASS(MyCustomType, godot::Node);
public:
    void calling();
    void functions();
    void works();
    void fine();
};

// ...

class Manager: public godot::Node
{
    GODOT_CLASS(Manager, godot::Node);
public:
    MyCustomType* make_custom_object()
    {
        auto object = MyCustomType::_new();
        add_child(object);
        return object;
    }
};

The .gdns file:

[gd_resource type="NativeScript" load_steps=2 format=2]

[ext_resource path="res://bin/test.gdnlib" type="GDNativeLibrary" id=1]

[resource]
class_name = "MyCustomType"
library = ExtResource( 1 )
script_class_name = "MyCustomType"

GDScript:

var o = Manager.make_custom_object()

o.calling()
o.functions()
o.works()
o.fine()

var test:MyCustomType = o #error

image

Also, if the variable is a function parameter, e.g.:

func broken(param:MyCustomType):
    pass

# ...

var o = Manager.make_custom_object()

broken(o)

...then no runtime error is produced, but param will be null

Metadata

Metadata

Assignees

No one assigned

    Labels

    waiting for GodotThis issue needs a Godot Engine improvement to be solved

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions