godotengine / godotengine/godot-cpp

godot::Object::cast_to() always returns nullptr when target is user defined class

Open
#217 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
2.7k
Forks
809
Avg merge
1d 3h
Merged PRs (30d)
8

Description

Inside `godot::register_class()` we have
`_TagDB::register_type(typeid(T).hash_code(), typeid(T).hash_code());`
The first and second arguments always have the same value

The definition of `_TagDB::register_type()` is
```
void register_type(size_t type_tag, size_t base_type_tag) {
if (type_tag == base_type_tag) {
return;
}
parent_to[type_tag] = base_type_tag;
}
```

Hence it will immediately return and it won't register the custom type tag as a child of the actual parent.
Calling `cast_to()` won't be able to resolve the casting.
I think the call should be something like
`_TagDB::register_type(typeid(T).hash_code(), typeid(T::BaseT).hash_code());`
where `BaseT` is defined by the `GODOT_CLASS()` macro for T

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.