Skip to content

Commit 40553af

Browse files
committed
fix: null check for cache ref
1 parent ab2c566 commit 40553af

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Scripts/Runtime/Core/ScriptableObjectCollectionItem.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public override bool Equals(object o)
108108
ScriptableObjectCollectionItem other = o as ScriptableObjectCollectionItem;
109109
if (other == null)
110110
return false;
111-
111+
112112
return guid.IsValid() && other.guid.IsValid() && guid == other.guid;
113113
}
114114

@@ -117,10 +117,12 @@ public override bool Equals(object o)
117117
if (ReferenceEquals(left, right))
118118
return true;
119119

120-
if (ReferenceEquals(left, null))
121-
return false;
122-
123-
if (ReferenceEquals(right, null))
120+
// Use Unity's implicit bool to detect destroyed objects
121+
bool leftNull = ReferenceEquals(left, null) || !(UnityEngine.Object)left;
122+
bool rightNull = ReferenceEquals(right, null) || !(UnityEngine.Object)right;
123+
if (leftNull && rightNull)
124+
return true;
125+
if (leftNull || rightNull)
124126
return false;
125127

126128
return left.Equals(right);

0 commit comments

Comments
 (0)