From b1385953fe304a2e7713ca2e0fbf3329842b94f0 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Tue, 8 Mar 2022 10:11:34 +0200 Subject: [PATCH] Add `ObjectDB::get_instance` method to get wrapped `Object *` from `ObjectID`. --- include/godot_cpp/core/object.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/godot_cpp/core/object.hpp b/include/godot_cpp/core/object.hpp index 658f9be9..b3bacb98 100644 --- a/include/godot_cpp/core/object.hpp +++ b/include/godot_cpp/core/object.hpp @@ -134,6 +134,17 @@ MethodInfo::MethodInfo(const PropertyInfo &p_ret, const char *p_name, const Args arguments = { args... }; } +class ObjectDB { +public: + static Object *get_instance(uint64_t p_object_id) { + GDNativeObjectPtr obj = internal::gdn_interface->object_get_instance_from_id(p_object_id); + if (obj == nullptr) { + return nullptr; + } + return reinterpret_cast(internal::gdn_interface->object_get_instance_binding(obj, internal::token, &Object::___binding_callbacks)); + } +}; + template T *Object::cast_to(Object *p_object) { GDNativeObjectPtr casted = internal::gdn_interface->object_cast_to(p_object->_owner, internal::gdn_interface->classdb_get_class_tag(T::get_class_static()));