summaryrefslogtreecommitdiff
path: root/modules/mono
diff options
context:
space:
mode:
authorRaul Santos <raulsntos@gmail.com>2021-10-08 20:00:47 +0200
committerRaul Santos <raulsntos@gmail.com>2021-10-08 20:00:47 +0200
commit0be9664b42e38a62ffd5adcacf75eca449fbdf02 (patch)
treefd397922d36358442ba5d43f8fda62e1024f8d06 /modules/mono
parenta5a52233bc1327d8943c0a2a3866aa314371edec (diff)
Support marshaling generic Godot.Object
Allows using generic C# types in signals as long as they inherit from `Godot.Object`.
Diffstat (limited to 'modules/mono')
-rw-r--r--modules/mono/mono_gd/gd_mono_marshal.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/modules/mono/mono_gd/gd_mono_marshal.cpp b/modules/mono/mono_gd/gd_mono_marshal.cpp
index c9789bf270..fd30c7737d 100644
--- a/modules/mono/mono_gd/gd_mono_marshal.cpp
+++ b/modules/mono/mono_gd/gd_mono_marshal.cpp
@@ -266,6 +266,12 @@ Variant::Type managed_to_variant_type(const ManagedType &p_type, bool *r_nil_is_
if (GDMonoUtils::Marshal::type_is_generic_icollection(reftype) || GDMonoUtils::Marshal::type_is_generic_ienumerable(reftype)) {
return Variant::ARRAY;
}
+
+ // GodotObject
+ GDMonoClass *type_class = p_type.type_class;
+ if (CACHED_CLASS(GodotObject)->is_assignable_from(type_class)) {
+ return Variant::OBJECT;
+ }
} break;
default: {
@@ -450,6 +456,11 @@ MonoObject *variant_to_mono_object_of_genericinst(const Variant &p_var, GDMonoCl
return GDMonoUtils::create_managed_from(p_var.operator Array(), godot_array_class);
}
+ // GodotObject
+ if (CACHED_CLASS(GodotObject)->is_assignable_from(p_type_class)) {
+ return GDMonoUtils::unmanaged_get_managed(p_var.operator Object *());
+ }
+
ERR_FAIL_V_MSG(nullptr, "Attempted to convert Variant to unsupported generic type: '" +
p_type_class->get_full_name() + "'.");
}