Skip to content

Commit 489ec64

Browse files
committed
fix(id repair): null and empty string IDs are now repaired
1 parent 53193c4 commit 489ec64

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Assets/Examples/Resources/ItemDatabase.asset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ MonoBehaviour:
1212
m_Script: {fileID: 11500000, guid: a600bc502ed14cf5980ca274873f182a, type: 3}
1313
m_Name: ItemDatabase
1414
m_EditorClassIdentifier:
15+
_autoLoad: 1
1516
_definitions:
1617
- {fileID: 11400000, guid: d3988ba3f8a2c44e6a1b98201ce75ee2, type: 2}
1718
- {fileID: 11400000, guid: 4e2438a1b36c043e587e88575d07b5ff, type: 2}

Assets/com.fluid.elastic-inventory/Editor/Scripts/ItemDatabase/ItemDatabaseEditor.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ private void FixDuplicateItemIds () {
6565
so.ApplyModifiedProperties();
6666
EditorUtility.SetDirty(definition);
6767

68+
count++;
69+
} else if (string.IsNullOrEmpty(definition.Id)) {
70+
var newId = System.Guid.NewGuid().ToString();
71+
Debug.LogWarning($"Empty ID in {path}. Randomizing the ID to {newId}.");
72+
73+
var so = new SerializedObject(definition);
74+
var idField = so.FindProperty("_id");
75+
idField.stringValue = newId;
76+
77+
so.ApplyModifiedProperties();
78+
EditorUtility.SetDirty(definition);
79+
6880
count++;
6981
} else {
7082
ids.Add(definition.Id);

0 commit comments

Comments
 (0)