[Bug] Demo database duplicate error

Cheo

Active member
Hello, I was watching the first tutorial video for UIS named "Basic Concepts" this morning and tried duplicating the demo inventory database as shown in the video, but when pressing play in a duplicate of the demo scene using the duplicate of the inventory database I stumbled upon an error related to a "Wand" object :

Code:
[Error] The object "Wand" with ID 1356961972 is not part of the active database. Please run the 'Replace Database Objects' script by right-clicking on the folder with the affected prefabs, scriptable objects, or scenes.
Opsive.UltimateInventorySystem.Core.ObjectCategoryBase`2<Opsive.UltimateInventorySystem.Core.ItemCategory, Opsive.UltimateInventorySystem.Core.ItemDefinition>.InherentlyContains() at /Opsive/UltimateInventorySystem/Scripts/Core/ObjectCategoryBase.cs:499
 497:  {
 498:      if (IsInitialized == false) {
--> 499:          Debug.LogError($"The object \"{this}\" with ID {m_ID} is not part of the active database. " +
 500:                         $"Please run the 'Replace Database Objects' script by right-clicking on the folder with the affected prefabs, scriptable objects, or scenes.");
 501:          return false;

ItemCategory.InherentlyContains() at /Opsive/UltimateInventorySystem/Scripts/Core/ItemCategory.cs:1045
1043:  public bool InherentlyContains(ItemDefinitionBase itemDefinition, bool includeThis = true)
1044:  {
-->1045:      return base.InherentlyContains(itemDefinition as ItemDefinition, includeThis);
1046:  }

ItemCategory.InherentlyContains() at /Opsive/UltimateInventorySystem/Scripts/Core/ItemCategory.cs:1004
1002:  public bool InherentlyContains(Item item, bool includeThis = true)
1003:  {
-->1004:      return InherentlyContains(item?.ItemDefinition, includeThis);
1005:  }

ItemBinding.SetItem() at /Opsive/UltimateInventorySystem/Scripts/Core/ItemBinding.cs:197
 195:  }
--> 197:  if (m_ItemCategory.InherentlyContains(item) == false) {
 198:      Debug.LogWarning($"The item specified ({item}) does not match item category that was set on the binding ({m_ItemCategory}).");
 199:      m_Item = null;

ItemBinding.SetItemObject() at /Opsive/UltimateInventorySystem/Scripts/Core/ItemBinding.cs:106
 105:      EventHandler.RegisterEvent(m_ItemObject, EventNames.c_ItemObject_OnItemChanged, SetItem);
--> 106:      SetItem(m_ItemObject.Item);
 107:  }

ItemBinding.Start() at /Opsive/UltimateInventorySystem/Scripts/Core/ItemBinding.cs:73
  71:  var itemObject = GetComponent<ItemObject>();
  72:  if (itemObject != null) {
-->  73:      SetItemObject(itemObject);
  74:  }
  75:  if (m_ItemObject != null) { return; }

4 more errors related to Iron Sword and Knight Armor can be thrown when selecting "Duplicate all referenced prefabs" when duplicating the database :

Code:
[Error] The Prefab attribute value is null, please assign a default value or in the attribute, make sure the item Knight Armor (2502941901) has a non-null value for attribute: PickupPrefab.
ItemVisualizerBase.SetVisualInternal() at /Opsive/UltimateInventorySystem/Scripts/DropsAndPickups/ItemVisualizerBase.cs:145
 144:  if (prefab == null) {
--> 145:      Debug.LogError($"The Prefab attribute value is null, please assign a default value or " +
 146:                     $"in the attribute, make sure the item {item} has a non-null value " +
 147:                     $"for attribute: {m_PrefabAttributeName}.");

ItemVisualizerBase.UpdateVisual() at /Opsive/UltimateInventorySystem/Scripts/DropsAndPickups/ItemVisualizerBase.cs:89
  87:      }
-->  89:      SetVisualInternal(itemInfo);
  90:  }

ItemObjectVisualizer.UpdateVisual() at /Opsive/UltimateInventorySystem/Scripts/DropsAndPickups/ItemObjectVisualizer.cs:55
  53:          return;
  54:      }
-->  55:      UpdateVisual(m_ItemObject.ItemInfo);
  56:  }

ItemVisualizerBase.OnEnable() at /Opsive/UltimateInventorySystem/Scripts/DropsAndPickups/ItemVisualizerBase.cs:74
  72:  protected virtual void OnEnable()
  73:  {
-->  74:      UpdateVisual();
  75:  }

ItemObjectVisualizer.OnEnable() at /Opsive/UltimateInventorySystem/Scripts/DropsAndPickups/ItemObjectVisualizer.cs:46
  44:      }
-->  46:      base.OnEnable();
  47:  }

Here is a video showing all this, I also took the time to double check in a fresh project and confirm it happened in it as well :


As I say in the video, it's a bit annoying because we can't reproduce what is shown at the end of the tutorial video, even though the duplication process is quite fast and simple and should allow different databases to work seamlessly across different scenes. Hope this was useful and that the issue can be fixed. Thanks in advance.
 
Thank you Cheo as usual I really appriciate you making a detailed bug report including a video.

To give a bit more context on why you are getting this first error.
The database is a list of interconnected scriptable objects. This scriptableobjects are referenced by gameobjects in scenes and prefabs.
When you duplicate a database, you duplicate the scriptable objects. At that point the gameobjects in the scenes and prefabs are still referencing the objects from the previous database.

When you right click on a scene a select update database, we have a script that scans all the objects in the scene and tries to find (the best it can) all references to the objects from the previous database and replaces them with the new references that match the same ID or name.

But since you right clicked on the scene, and not a folder, it will only update the scene. Not the prefabs.

By right clicking on the folder and replacing the database this will update all the scenes, prefabs and scriptable objects inside
1695630182632.png
Notice the wording in the error message:
[Error] The object "Wand" with ID 1356961972 is not part of the active database. Please run the 'Replace Database Objects' script by right-clicking on the folder with the affected prefabs, scriptable objects, or scenes.

If you do this you'll notice how there are no errors in the console when you press play.

That being said I am getting errors when doing the Duplicate prefabs option of duplicating the database. It seems the prefab are getting duplicated but they are not being assigned to attributes and they aren't being converted to the new database. I wonder if they aren't being dirtied properly causing them to not save properly before the database duplication finishes.
I will look into that in more detail.

You can find the duplicated prefabs in "<Duplicate database name>/prefabs/"
This should be done automatically during duplication. But just in case you may want to update the duplicated prefabs:
1695632019099.png




Now in some cases the automatic replace database object script might not work. So you may need to fix things manually. Here is how I go about doing it.
1695631356221.png

1) Check the error message, and find the object causing the error (You can type the object type in the hierarchy and it will show all gameobjects with that component).
In this case I'm lucky, there is only one. In case there is more you'll need to scroll to find the object that has a warning in it's inspector.

2) We see that the faulty gameobject has "(Clone)" in its name, so we know it's a prefab that was spawned at runtime.
We can find that prefab by name in the project window. (If you have duplicated the prefabs ensure it's the right one).
Then press the convert object.
1695631865827.png
The warning should go away and you'll see the inspector properly
1695631926574.png
 
Finally for the attribute null issue. you can fix it manually for now too. You can set it to inherit or assign the duplicated prefab (which should have been done automatically. As I said above I'll look into why that's not the case)
1695632263436.png

I hope this in depth run through helps you out.
And again, thank you for pointing out the errors
 
Hello, thank you very much for this detailed and thorough answer.

I must however inform you that the conversion process doesn't solve the issues on my end even when selecting the base Opsive folder (I should have mentioned that in the video sorry), could you please confirm whether or not it works on your end in a fresh project when selecting "Keep references to prefabs" ?

The manual fixes you showed for the Wand, Iron Sword and Knight Armor work perfectly, I don't have any errors related to them now !

One more thing if I may : I see that you're using Unity's console, I recommend to anyone still doing that and with a little cash to spare to use Editor Console Pro instead : https://assetstore.unity.com/packages/tools/utilities/editor-console-pro-11889
It's the first asset I import into any new project, please check it out, it'll be especially useful for you as a developer !

One last thing : I noticed that the "Player Character Invenvtory Variant" (little typo btw) has missing scripts, 3 of them more specifically, don't know which exactly, you should take a look at that as well.

Thanks again for your attention.
 
I must however inform you that the conversion process doesn't solve the issues on my end even when selecting the base Opsive folder (I should have mentioned that in the video sorry), could you please confirm whether or not it works on your end in a fresh project when selecting "Keep references to prefabs" ?
That's odd, I've tested it in a new project and I didn't have any errors.
I wonder if it has something to do with the Unity version or if it's something that can randomly fail.

One last thing : I noticed that the "Player Character Invenvtory Variant" (little typo btw) has missing scripts, 3 of them more specifically, don't know which exactly, you should take a look at that as well.
Feel free to remove those missing components

ne last thing : I noticed that the "Player Character Invenvtory Variant" (little typo btw) has missing scripts, 3 of them more specifically, don't know which exactly, you should take a look at that as well.
Thanks for letting me know. It seems this is a prefab that should have been deleted. I'm going to remove it now. Thanks for letting me know
 
I wonder if it has something to do with the Unity version or if it's something that can randomly fail.
Yes, this seems to be about the Unity version ! I just tried in a fresh project using 2021.3.25f1, redownloaded UIS and duplicated the demo while selecting "Keep references to prefabs", and got no error when playing the demo ! I invite you to give another try with one of the latest 2022.3 LTS versions - for my part I maintain that the issue occured on 2022.3.7 and 10 for sure.

No problem for the character with missing scripts, I saw it mentioned in an error in the console, but other than that it's neither useful nor problematic, so yeah apparently you might as well delete it.

Thanks again for following these issues.
 
Top