Skip to content

Commit

Permalink
fix(id repair): null and empty string IDs are now repaired
Browse files Browse the repository at this point in the history
  • Loading branch information
ashblue committed Jan 11, 2025
1 parent 53193c4 commit 489ec64
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions Assets/Examples/Resources/ItemDatabase.asset
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a600bc502ed14cf5980ca274873f182a, type: 3}
m_Name: ItemDatabase
m_EditorClassIdentifier:
_autoLoad: 1
_definitions:
- {fileID: 11400000, guid: d3988ba3f8a2c44e6a1b98201ce75ee2, type: 2}
- {fileID: 11400000, guid: 4e2438a1b36c043e587e88575d07b5ff, type: 2}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ private void FixDuplicateItemIds () {
so.ApplyModifiedProperties();
EditorUtility.SetDirty(definition);

count++;
} else if (string.IsNullOrEmpty(definition.Id)) {
var newId = System.Guid.NewGuid().ToString();
Debug.LogWarning($"Empty ID in {path}. Randomizing the ID to {newId}.");

var so = new SerializedObject(definition);
var idField = so.FindProperty("_id");
idField.stringValue = newId;

so.ApplyModifiedProperties();
EditorUtility.SetDirty(definition);

count++;
} else {
ids.Add(definition.Id);
Expand Down

0 comments on commit 489ec64

Please sign in to comment.