godotengine / godotengine/godot-cpp

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

Open
#430 16 comments 0 reactions 0 assignees View on GitHub
waiting for Godot
Dominant language
C++
Stars
2.7k
Forks
809
Avg merge
1d 3h
Merged PRs (30d)
8

Description

GDNative:
```c++
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:
```gdscript
var o = Manager.make_custom_object()

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

var test:MyCustomType = o #error
```
![image](https://user-images.githubusercontent.com/68328892/88051744-03841a00-cb51-11ea-9a22-200c2f70ec38.png)

Also, if the variable is a function parameter, e.g.:
```gdscript
func broken(param:MyCustomType):
pass

# ...

var o = Manager.make_custom_object()

broken(o)
```
...then no runtime error is produced, but param will be `null`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.