diff --git a/Assets/Mirror/Runtime/SyncVarGameObject.cs b/Assets/Mirror/Runtime/SyncVarGameObject.cs index 284ac9555..81e50cbf0 100644 --- a/Assets/Mirror/Runtime/SyncVarGameObject.cs +++ b/Assets/Mirror/Runtime/SyncVarGameObject.cs @@ -127,5 +127,9 @@ static GameObject GetGameObject(uint netId) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(GameObject a, SyncVarGameObject b) => !(a == b); + + // if we overwrite == operators, we also need to overwrite .Equals. + public override bool Equals(object obj) => obj is SyncVarGameObject value && this == value; + public override int GetHashCode() => Value.GetHashCode(); } } diff --git a/Assets/Mirror/Runtime/SyncVarNetworkBehaviour.cs b/Assets/Mirror/Runtime/SyncVarNetworkBehaviour.cs index f09f7e915..16adc93b6 100644 --- a/Assets/Mirror/Runtime/SyncVarNetworkBehaviour.cs +++ b/Assets/Mirror/Runtime/SyncVarNetworkBehaviour.cs @@ -80,6 +80,10 @@ public SyncVarNetworkBehaviour(T value = null) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(NetworkBehaviour a, SyncVarNetworkBehaviour b) => !(a == b); + // if we overwrite == operators, we also need to overwrite .Equals. + public override bool Equals(object obj) => obj is SyncVarNetworkBehaviour value && this == value; + public override int GetHashCode() => Value.GetHashCode(); + // helper functions to get/set netId, componentIndex from ulong internal static ulong Pack(uint netId, byte componentIndex) { diff --git a/Assets/Mirror/Runtime/SyncVarNetworkIdentity.cs b/Assets/Mirror/Runtime/SyncVarNetworkIdentity.cs index aff6d2297..8f1cea4f5 100644 --- a/Assets/Mirror/Runtime/SyncVarNetworkIdentity.cs +++ b/Assets/Mirror/Runtime/SyncVarNetworkIdentity.cs @@ -102,5 +102,9 @@ public SyncVarNetworkIdentity(NetworkIdentity value = null) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(NetworkIdentity a, SyncVarNetworkIdentity b) => !(a == b); + + // if we overwrite == operators, we also need to overwrite .Equals. + public override bool Equals(object obj) => obj is SyncVarNetworkIdentity value && this == value; + public override int GetHashCode() => Value.GetHashCode(); } }