From 6c499e877f41e2debf065cb44844775057b09d61 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 2 Jun 2025 11:50:10 +0200 Subject: [PATCH] Fix prefab diff in Editor on mesh reference --- Source/Engine/Level/MeshReference.cs | 22 +++++++++++++++++++ Source/Engine/Serialization/JsonSerializer.cs | 9 +++++++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 Source/Engine/Level/MeshReference.cs diff --git a/Source/Engine/Level/MeshReference.cs b/Source/Engine/Level/MeshReference.cs new file mode 100644 index 000000000..14ef0c72b --- /dev/null +++ b/Source/Engine/Level/MeshReference.cs @@ -0,0 +1,22 @@ +// Copyright (c) Wojciech Figat. All rights reserved. + + +using FlaxEngine.Json; + +namespace FlaxEngine +{ + partial class ModelInstanceActor + { + partial struct MeshReference : ICustomValueEquals + { + /// + public bool ValueEquals(object other) + { + var o = (MeshReference)other; + return JsonSerializer.ValueEquals(Actor, o.Actor) && + LODIndex == o.LODIndex && + MeshIndex == o.MeshIndex; + } + } + } +} diff --git a/Source/Engine/Serialization/JsonSerializer.cs b/Source/Engine/Serialization/JsonSerializer.cs index de1556577..4321ffa36 100644 --- a/Source/Engine/Serialization/JsonSerializer.cs +++ b/Source/Engine/Serialization/JsonSerializer.cs @@ -27,6 +27,11 @@ namespace FlaxEngine.Json } } + internal interface ICustomValueEquals + { + bool ValueEquals(object other); + } + partial class JsonSerializer { internal class SerializerCache @@ -262,7 +267,7 @@ namespace FlaxEngine.Json return true; if (objA == null || objB == null) return false; - + // Special case when saving reference to prefab object and the objects are different but the point to the same prefab object // In that case, skip saving reference as it's defined in prefab (will be populated via IdsMapping during deserialization) if (objA is SceneObject sceneA && objB is SceneObject sceneB && sceneA && sceneB && sceneA.HasPrefabLink && sceneB.HasPrefabLink) @@ -311,6 +316,8 @@ namespace FlaxEngine.Json return !bEnumerator.MoveNext(); } + if (objA is ICustomValueEquals customValueEquals && objA.GetType() == objB.GetType()) + return customValueEquals.ValueEquals(objB); return objA.Equals(objB); #endif }