diff --git a/include/core/Godot.hpp b/include/core/Godot.hpp index 478963283..528d5bf1b 100644 --- a/include/core/Godot.hpp +++ b/include/core/Godot.hpp @@ -42,11 +42,15 @@ public: godot::NativeScript *script = godot::NativeScript::_new(); \ script->set_library(godot::get_wrapper((godot_object *)godot::gdnlib)); \ script->set_class_name(#Name); \ - Name *instance = godot::as(script->new_()); \ + Variant instance_variant = script->new_(); \ + Reference *instance_ref = Object::cast_to(Object::___get_from_variant(instance_variant)); \ + if (instance_ref) \ + instance_ref->reference(); \ + Name *instance = godot::as(instance_variant); \ return instance; \ } \ - inline static size_t ___get_id() { return typeid(Name).hash_code(); } \ - inline static size_t ___get_base_id() { return typeid(Base).hash_code(); } \ + inline static size_t ___get_id() { return typeid(Name).hash_code(); } \ + inline static size_t ___get_base_id() { return typeid(Base).hash_code(); } \ inline static const char *___get_base_type_name() { return Base::___get_class_name(); } \ inline static Object *___get_from_variant(godot::Variant a) { return (godot::Object *)godot::as(godot::Object::___get_from_variant(a)); } \ \ @@ -62,7 +66,11 @@ public: godot::NativeScript *script = godot::NativeScript::_new(); \ script->set_library(godot::get_wrapper((godot_object *)godot::gdnlib)); \ script->set_class_name(#Name); \ - Name *instance = godot::as(script->new_()); \ + Variant instance_variant = script->new_(); \ + Reference *instance_ref = Object::cast_to(Object::___get_from_variant(instance_variant)); \ + if (instance_ref) \ + instance_ref->reference(); \ + Name *instance = godot::as(instance_variant); \ return instance; \ } \ inline static size_t ___get_id() { return typeid(Name).hash_code(); }; \