Bug: Duplicated item keeps old DefaultItem name in asset file

fablechris

New member
We're running into an issue where duplicated items keep their auto-generated name even after saving the database.
UIS version 1.2
Bug occurs on both OSX and WIndows

Repro steps:
  • Select an existing item (e.g. Sword)
  • Right-click > duplicate
  • Select the new item (now called Sword_1)
  • Rename the item in the Name field of the UIS editor to "Shield"
  • A new asset is created under the ItemDefinitions folder with the correct name "Shield"
  • Use CTRL+S or File > Save to save the database
  • Inspect the asset file in a text editor and observe that the m_DefaultItem: m_Name: field still holds a reference to the old name "Sword_1"
 
You are right... I never noticed that.

I have two solutions.
Either I never give the Item a name which will default to using the ItemDefinition name since the getter is:
Code:
get => string.IsNullOrWhiteSpace(m_Name) == false ? m_Name : m_ItemDefinition?.name ?? "NULL";

Or I replace the name when renaming the item definition.

I am tempted to go with the first solution since it would work in more scenarios in case I'm missing something other than renaming the itemdefinition.

But either solution won't fix existing databases I'm afraid.

I think the main reason I never noticed is that when the item is initialized it will use the item definition name. So at runtime it should always have the correct name.
1658392394971.png
 
I'm just now seeing that there's a warning printed when we first rename the item after duplicating:

Main Object Name 'TestItem' does not match filename 'Americano_1'
UnityEngine.StackTraceUtility:ExtractStackTrace ()
Opsive.UltimateInventorySystem.Editor.Managers.InventorySystemObjectBaseManager`1<Opsive.UltimateInventorySystem.Core.ItemDefinition>:<BuildVisualElements>b__8_0 (UnityEngine.UIElements.ChangeEvent`1<string>) (at Packages/upm-ultimate-inventory/UltimateInventorySystem/Editor/Managers/InventorySystemObjectBaseManager.cs:75)
UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

In this case TestItem was the new name we wanted to use.

One workaround we found is to edit one of the new item's parameters temporarily, save it, then change it back, save it again, and the item definition name is now what we expect.

The reason we noticed this behavior in the first place is that when creating items via InventorySystemManager.CreateItem(itemInfo.Item), the name of the item was wrong even though it was shown correctly in the UIS database UI. It seems that there is just a bug that is not updating the itemDefinition name when an item is renamed, unless I'm not understanding correctly.

Thanks for your help!
Chris
 
Careful I think you might be misunderstanding.
The ItemDefinition is the scriptable Object. Its name will always be the name that you see in the Editor or in the project folder.

The Item can have a different name. This was added such that you can customise the name of an item at runtime.

When duplicating an ItemDefinition and renaming it. you are changing the item definition name. The one that doesn't change is the default item name.

I will change the code to make sure the item name matches the item definition name when it is renamed. It will be available in a future update.

But the part I'm not sure I understand is how your item uses the wrong name when I update the name when it is initialized.

The only thing that should be able to do that is the save system which saves the item name and applies it after the item is initialized.
 
Last edited:
Top