Skip to content

Commit 8a3faaa

Browse files
committed
Merge pull request #1037 from dsnopek/fix-object-cast-to
Fix Object::cast_to<T>() for custom classes
2 parents f9ccf28 + 75af900 commit 8a3faaa

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/godot_cpp/core/object.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ T *Object::cast_to(Object *p_object) {
142142
if (casted == nullptr) {
143143
return nullptr;
144144
}
145-
return reinterpret_cast<T *>(internal::gde_interface->object_get_instance_binding(casted, internal::token, &T::___binding_callbacks));
145+
return dynamic_cast<T *>((Object *)internal::gde_interface->object_get_instance_binding(casted, internal::token, &T::___binding_callbacks));
146146
}
147147

148148
template <class T>
@@ -155,7 +155,7 @@ const T *Object::cast_to(const Object *p_object) {
155155
if (casted == nullptr) {
156156
return nullptr;
157157
}
158-
return reinterpret_cast<const T *>(internal::gde_interface->object_get_instance_binding(casted, internal::token, &T::___binding_callbacks));
158+
return dynamic_cast<const T *>((Object *)internal::gde_interface->object_get_instance_binding(casted, internal::token, &T::___binding_callbacks));
159159
}
160160

161161
} // namespace godot

0 commit comments

Comments
 (0)