godotengine / godotengine/godot-cpp
Objects instanced in c++ can't be bound to typed gdscript variables
- 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
```

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.