Skip to content

Commit b808130

Browse files
committed
fix: guid reserialization when not needed
1 parent 1d7acb2 commit b808130

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

Scripts/Runtime/Core/ScriptableObjectCollectionItem.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,7 @@ public class ScriptableObjectCollectionItem : ScriptableObject, IComparable<Scri
77
{
88
[SerializeField, HideInInspector]
99
private LongGuid guid;
10-
public LongGuid GUID
11-
{
12-
get
13-
{
14-
if (guid.IsValid())
15-
return guid;
16-
17-
GenerateNewGUID();
18-
return guid;
19-
}
20-
}
10+
public LongGuid GUID => guid;
2111

2212
[SerializeField, CollectionReferenceLongGuid]
2313
private LongGuid collectionGUID;
@@ -68,6 +58,16 @@ public int Index
6858
return cachedIndex;
6959
}
7060
}
61+
62+
#if UNITY_EDITOR
63+
private void OnValidate()
64+
{
65+
if (!guid.IsValid())
66+
{
67+
GenerateNewGUID();
68+
}
69+
}
70+
#endif
7171

7272
public void SetCollection(ScriptableObjectCollection collection)
7373
{
@@ -108,8 +108,8 @@ public override bool Equals(object o)
108108
ScriptableObjectCollectionItem other = o as ScriptableObjectCollectionItem;
109109
if (other == null)
110110
return false;
111-
112-
return ReferenceEquals(this, other);
111+
112+
return guid.IsValid() && other.guid.IsValid() && guid == other.guid;
113113
}
114114

115115
public static bool operator==(ScriptableObjectCollectionItem left, ScriptableObjectCollectionItem right)
@@ -133,7 +133,7 @@ public override bool Equals(object o)
133133

134134
public override int GetHashCode()
135135
{
136-
return GUID.GetHashCode();
136+
return guid.IsValid() ? guid.GetHashCode() : 0;
137137
}
138138
}
139-
}
139+
}

0 commit comments

Comments
 (0)