From f045c4c283c7f4063ffb0bdd6d4f0266339b018c Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Wed, 9 Oct 2024 21:19:53 +0200 Subject: [PATCH] [.NET] Use `ObjectID` when converting `Variant` to `GodotObject` (cherry picked from commit bfcc389e21dcb8426ca4f1ba7efb2debf5139ec5) --- .../GodotSharp/Core/NativeInterop/InteropStructs.cs | 6 ++++++ .../GodotSharp/Core/NativeInterop/VariantUtils.cs | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs index dda776fee5f..cb180f9a8b3 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs @@ -455,6 +455,12 @@ namespace Godot.NativeInterop get => _data._m_obj_data.obj; } + public readonly ulong ObjectId + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _data._m_obj_data.id; + } + public void Dispose() { switch (Type) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs index a48e60a30f6..9e5df0fa5c3 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs @@ -485,7 +485,14 @@ namespace Godot.NativeInterop NativeFuncs.godotsharp_variant_as_rid(p_var); public static IntPtr ConvertToGodotObjectPtr(in godot_variant p_var) - => p_var.Type == Variant.Type.Object ? p_var.Object : IntPtr.Zero; + { + if (p_var.Type != Variant.Type.Object || p_var.ObjectId == 0) + { + return IntPtr.Zero; + } + + return NativeFuncs.godotsharp_instance_from_id(p_var.ObjectId); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static GodotObject ConvertToGodotObject(in godot_variant p_var)