Proper way to create an item via editor script?

Dreampriest

New member
I have an editor script that I use to automatically create my ammo items, but all the created items give me an error about missing attributes every time I recompile:

ItemDefinition AMMO_Freeze Gun is missing an ItemDefinition Attribute named 'Icon'.
UnityEngine.Debug:LogWarning (object)
Opsive.UltimateInventorySystem.Editor.Managers.DatabaseValidator:Validate (Opsive.UltimateInventorySystem.Core.ItemCategory,bool) (at Assets/Standard Assets/Opsive/UltimateInventorySystem/Editor/Managers/DatabaseValidator.cs:431)
Opsive.UltimateInventorySystem.Editor.Managers.DatabaseValidator:CheckIfValid (Opsive.UltimateInventorySystem.Storage.InventorySystemDatabase,bool) (at Assets/Standard Assets/Opsive/UltimateInventorySystem/Editor/Managers/DatabaseValidator.cs:104)
Opsive.UltimateInventorySystem.Editor.Managers.InventoryMainWindow:ValidateDatabase () (at Assets/Standard Assets/Opsive/UltimateInventorySystem/Editor/Managers/InventoryMainWindow.cs:315)
Opsive.UltimateInventorySystem.Editor.Managers.InventoryMainWindow:OnEnable () (at Assets/Standard Assets/Opsive/UltimateInventorySystem/Editor/Managers/InventoryMainWindow.cs:214)
The database is not valid. An autofix process will now run.
UnityEngine.Debug:LogWarning (object)
Opsive.UltimateInventorySystem.Editor.Managers.InventoryMainWindow:ValidateDatabase () (at Assets/Standard Assets/Opsive/UltimateInventorySystem/Editor/Managers/InventoryMainWindow.cs:317)
Opsive.UltimateInventorySystem.Editor.Managers.InventoryMainWindow:OnEnable () (at Assets/Standard Assets/Opsive/UltimateInventorySystem/Editor/Managers/InventoryMainWindow.cs:214)

The autofix doesn't seem to actually fix the error as it will keep displaying the message every time.

Here is the code I'm using to generate the items:

C#:
                var ammoitem = ItemDefinitionEditorUtility.AddItemDefinition("AMMO_" + itemDefinition.name, ammoCategory, database, DatabaseValidator.GetDatabaseDirectory(database));

                var newAmmoData = new AmmoData(ammoitem, ammoData.ClipSize, ammoData.ClipRemaining, ammoData.ReserveAmmoCount);
                ammoDataAttr.SetOverrideValue(newAmmoData);
                AttributeEditorUtility.SetVariantType(ammoDataAttr, VariantType.Override);
                ItemDefinitionEditorUtility.SetItemDefinitionDirty(itemDefinition, true);
 
I see one thing that could be the problem. On the last line you should dirty the "ammoItem" not the original ItemDefinition. Btw "ammoItem" should really be "ammoItemDefinition" to keep things well named.

You've made sure to Initialized the database before running this script correct?
your database is valid before you try to add the item definition correct?

Let me know if that fixes it
 
Looks like it's working now, thanks! I added a SetItemDefinitionDirty for the new item definition, and added an initialize check to the top of the function and I'm not getting warnings on new ammo definitions.
 
Top