Error caused by two UCC characters with a UIS inventory

Cheo

Active member
Hello, I've recently stumbled upon an annoying issue caused, I'm assuming, by the combination of UCC and UIS. If a UCC npc is given a UIS inventory, in addition to the player character already having one, we get an error on start. Here is a video showing the issue :


Here are the stack and source for the error :

Code:
[Exception] ArgumentException: An item with the same key has already been added. Key: 1976610244
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert() at <b89873cb176e44a995a4781c7487d410>:0

System.Collections.Generic.Dictionary`2[TKey,TValue].Add() at <b89873cb176e44a995a4781c7487d410>:0

Opsive.UltimateInventorySystem.Core.Registers.InventoryObjectIDOnlyRegister`1[T].AddInternal() at /Opsive/UltimateInventorySystem/Scripts/Core/Registers/InventoryObjectRegister.cs:297
 295:  protected virtual void AddInternal(T obj)
 296:  {
--> 297:      m_DictionaryByID.Add(obj.ID, obj);
 298:  }

Opsive.UltimateInventorySystem.Core.Registers.InventoryObjectIDOnlyRegister`1[T].RegisterInternal() at /Opsive/UltimateInventorySystem/Scripts/Core/Registers/InventoryObjectRegister.cs:285
 284:  if (addToDictionaries) {
--> 285:      AddInternal(obj);
 286:  }

Opsive.UltimateInventorySystem.Core.Registers.InventoryObjectIDOnlyRegister`1[T].Register() at /Opsive/UltimateInventorySystem/Scripts/Core/Registers/InventoryObjectRegister.cs:256
 254:  public virtual bool Register(T obj)
 255:  {
--> 256:      return RegisterInternal(obj);
 257:  }

InventoryIdentifier.RegisterIdentifier() at /Opsive/UltimateInventorySystem/Scripts/Core/InventoryCollections/InventoryIdentifier.cs:86
  84:      }
-->  86:      InventorySystemManager.InventoryIdentifierRegister.Register(this);
  87:  }

InventoryIdentifier.Awake() at /Opsive/UltimateInventorySystem/Scripts/Core/InventoryCollections/InventoryIdentifier.cs:59
  57:  public virtual void Awake()
  58:  {
-->  59:      RegisterIdentifier();
  60:  }

Two things I forgot to mention : I tried giving the UCC NPC I made in the integration demo scene has the exact same Inventory Item Set Manager component values as the Inventory Atlas's, as well as giving him a single basic item rule. That changed nothing, the error was there on start.

But most importantly, I made a simple test scene with no player and my default enemy and then with an additional duplicate of it - the results were the same, the scene could be run with a single enemy but not two.

Hope this issue can be taken a look at and fixed. If you think I made a mistake somewhere with my UCC-UIS setup, please do say so. In any case, the UCC-UIS integration demo scene definitely needs a UCC NPC in it, as an example and proof of functioning.
 
Sorry I haven't had time to look at your video in full.

But I believe your error is caused by having a multiple InventoryIdentifier IDs with the same ID.

Usually you shouldn't have InventoryIndentifier component on NPCs. Because they are not always unique.
For example if you have it on an NPC prefab that can be spawned multiple times at runtime, you must remove that component.

Either remove it, or set its ID to a unique ID.
1696606132791.png

That component is used for you to easily access your Inventory component trhough anywhere in the code by only knowing the ID.

Let me know if that was it, or if it was something else
 
Damn I feel a bit stupid, you're right the root of the issue was the Inventory Identifier, giving it a different ID or removing it fixes the issue.

I do maintain however that adding a simple UCC NPC with a UIS inventory to the integration demo scene would be a good thing.

In any case, thank you very much and have a good weekend !
 
Top