From b41a7935925a1f861f6230f8af5d91ef02c5c2d5 Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Thu, 14 Feb 2019 22:54:10 +0100 Subject: [PATCH] Fix Godot.Reference marshalling from MonoObject* to Variant Need to cast Ref to Variant instead of constructing Variant from Object*, otherwise the Variant won't hold a reference. --- modules/mono/mono_gd/gd_mono_marshal.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/mono/mono_gd/gd_mono_marshal.cpp b/modules/mono/mono_gd/gd_mono_marshal.cpp index 74395de41ce..18a49d0d1fc 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.cpp +++ b/modules/mono/mono_gd/gd_mono_marshal.cpp @@ -698,7 +698,11 @@ Variant mono_object_to_variant(MonoObject *p_obj) { // GodotObject if (CACHED_CLASS(GodotObject)->is_assignable_from(type_class)) { Object *ptr = unbox(CACHED_FIELD(GodotObject, ptr)->get_value(p_obj)); - return ptr ? Variant(ptr) : Variant(); + if (ptr != NULL) { + Reference *ref = Object::cast_to(ptr); + return ref ? Variant(Ref(ref)) : Variant(ptr); + } + return Variant(); } if (CACHED_CLASS(NodePath) == type_class) {