Custom Weapon Equips, but Doesn't Unequip

Hi,
I'm prototyping some game bits using UCC and UIS, with the Demo Item Collection (UCC) and the IntegtationDemoInventoryDatabase (UIS). I added all of the out of the box weapons to the Player Inventory/ Default Loadout component, using the UIS Item Definition. All of this works fine, no errors on Loadout, no errors when equipping or unequipping using the UIS Inventory System Canvas (Demo Full Layout). All weapons function perfectly.

I followed both tutorial videos to set up a custom Shootable Item, first with UCC (Item Type Manager), then with UIS (Item Definitions/Item Category Single Wield Gun), and added the custom item to the Inventory/Loadout. When using the UIS Inventory System Canvas to equip the custom item, I get the following error message:

ArgumentException: An item with the same key has already been added. Key: 0

The item still equips, and shoots, but when unequipping via the Inventory interface, the item stays in the Player's hand, the icon disappears from the Primary Weapon Slot, reappears in the Item View Slots Grid, and any further item that is equipped appears along with the custom item.

I fished around to try to find out where the Dictionary Tkey is assigned, but couldn't find anything. I also see that the error is coming from the UCC script CharacterItem, thought maybe it could be solved with the CharacterItem script ItemIdentifier (which debugs as (none), but couldn't figure out where to assign my own, or even if this is where the solution would be.

Any ideas on where I should be fiddling with this one?
 
Oops. The custom weapon doesnt spawn the prefab designated in the ShootableAction/ProjectileModuleGroup/SpawnProjectile either.
 
I'm sorry to hear you are having issues.
When copy pasting error messages, please copy paste the FULL stack, not just the error message. Otherwise we can't know where the issue came from.

My guess is that your custom weapon prefab is not setup properly. I would recommend you read the documentation about the integration, the section about setting up an item. Double check that you didn't miss a step:
 
Thanks for your reply.
I've deleted all the prefabs from my first attempt, and followed the video on integration step by step, then read along with the documentation.
I've done absolutely everything according to the guidelines (my weapon is a shootable item that should spawn a projectile. The projectile prefab has a character item script so that it links up to the inventory system, as well as a projectile script). No errors when entering play, but as soon as I equip the weapon via the inventory gui, I get the following error below. I've been over and over the weapon prefab, comparing it to out of the box prefabs (also the projectile prefabs), but I'm lost on this one.

Code:
NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem.InventoryAmmoDataClip.SetAmmoData (Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem.AmmoData ammoData, System.Boolean refreshAmmoList) (at Assets/Opsive/UltimateCharacterController/Integrations/UltimateInventorySystem/Scripts/ItemActionModules/InventoryAmmoDataClip.cs:135)
Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem.InventoryAmmoDataClip.set_AmmoData (Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem.AmmoData value) (at Assets/Opsive/UltimateCharacterController/Integrations/UltimateInventorySystem/Scripts/ItemActionModules/InventoryAmmoDataClip.cs:80)
Opsive.UltimateInventorySystem.Core.GenericAttributeBinding`1[T].Refresh () (at Assets/Opsive/UltimateInventorySystem/Scripts/Core/AttributeBinding.cs:223)
Opsive.UltimateInventorySystem.Core.GenericAttributeBinding`1[T].BindAttribute (Opsive.UltimateInventorySystem.Core.AttributeSystem.Attribute`1[T] attribute) (at Assets/Opsive/UltimateInventorySystem/Scripts/Core/AttributeBinding.cs:202)
Opsive.UltimateInventorySystem.Core.GenericAttributeBinding`1[T].BindAttribute (Opsive.UltimateInventorySystem.Core.AttributeSystem.AttributeBase attribute) (at Assets/Opsive/UltimateInventorySystem/Scripts/Core/AttributeBinding.cs:186)
Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem.ItemObjectBinding.BindAttribute (Opsive.UltimateInventorySystem.Core.AttributeSystem.AttributeBase attribute) (at Assets/Opsive/UltimateCharacterController/Integrations/UltimateInventorySystem/Scripts/Bindings/ItemObjectBinding.cs:269)
Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem.ItemObjectBinding.SetItem (Opsive.UltimateInventorySystem.Core.Item item) (at Assets/Opsive/UltimateCharacterController/Integrations/UltimateInventorySystem/Scripts/Bindings/ItemObjectBinding.cs:241)
Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem.ItemObjectBinding.SetItemObject (Opsive.UltimateInventorySystem.Core.ItemObject itemObject) (at Assets/Opsive/UltimateCharacterController/Integrations/UltimateInventorySystem/Scripts/Bindings/ItemObjectBinding.cs:190)
Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem.ItemObjectBinding.InitializeInternal () (at Assets/Opsive/UltimateCharacterController/Integrations/UltimateInventorySystem/Scripts/Bindings/ItemObjectBinding.cs:82)
Opsive.UltimateCharacterController.Items.Actions.Bindings.StateObjectBinding.Initialize (Opsive.Shared.StateSystem.StateObject boundStateObject, UnityEngine.GameObject boundGameObject) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/Bindings/StateObjectBinding.cs:116)
Opsive.UltimateCharacterController.Items.Actions.Bindings.StateObjectBindingGroup.Initialize (Opsive.Shared.StateSystem.StateObject boundStateObject, UnityEngine.GameObject boundGameObject) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/Bindings/StateObjectBinding.cs:88)
Opsive.UltimateCharacterController.Items.Actions.Bindings.BoundStateObject.InitializeStateObjectBindings (UnityEngine.GameObject boundGameObject) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/Bindings/StateObjectBinding.cs:53)
Opsive.UltimateCharacterController.Items.Actions.Bindings.BoundStateObject.InitializeStateObjectBindings () (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/Bindings/StateObjectBinding.cs:44)
Opsive.UltimateCharacterController.Items.Actions.Bindings.BoundStateObject.Initialize (UnityEngine.GameObject gameObject) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/Bindings/StateObjectBinding.cs:34)
Opsive.UltimateCharacterController.Items.Actions.Modules.ActionModule.Initialize (Opsive.UltimateCharacterController.Items.Actions.CharacterItemAction itemAction) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/Modules/ActionModule.cs:177)
 
The other half of the error stack:

Code:
Opsive.UltimateCharacterController.Items.Actions.ShootableActionModule.Initialize (Opsive.UltimateCharacterController.Items.Actions.CharacterItemAction itemAction) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/ShootableAction.cs:70)

Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem.InventoryAmmoDataClip.Initialize (Opsive.UltimateCharacterController.Items.Actions.CharacterItemAction itemAction) (at Assets/Opsive/UltimateCharacterController/Integrations/UltimateInventorySystem/Scripts/ItemActionModules/InventoryAmmoDataClip.cs:108)

Opsive.UltimateCharacterController.Items.Actions.Modules.ActionModule.Initialize (Opsive.UltimateCharacterController.Items.Actions.CharacterItemAction itemAction, Opsive.UltimateCharacterController.Items.Actions.Modules.ActionModuleGroupBase moduleGroup) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/Modules/ActionModule.cs:161)

Opsive.UltimateCharacterController.Items.Actions.Modules.ActionModuleGroup`1[T].OnModuleAdded (T module, UnityEngine.GameObject gameObject) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/Modules/ActionModuleGroup.cs:502)

Opsive.UltimateCharacterController.Items.Actions.Modules.ActionModuleGroup`1[T].Initialize (Opsive.UltimateCharacterController.Items.Actions.CharacterItemAction characterItemAction) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/Modules/ActionModuleGroup.cs:326)

Opsive.UltimateCharacterController.Items.Actions.CharacterItemAction.InitializeModuleGroups (System.Boolean force) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/CharacterItemAction.cs:222)

Opsive.UltimateCharacterController.Items.Actions.CharacterItemAction.InitializeAction (System.Boolean force) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/CharacterItemAction.cs:149)

Opsive.UltimateCharacterController.Items.CharacterItem.Initialize (System.Boolean force) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/CharacterItem.cs:286)

Opsive.UltimateCharacterController.Items.CharacterItem.Initialize (Opsive.Shared.Inventory.IItemIdentifier itemIdentifier) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/CharacterItem.cs:367)

Opsive.UltimateCharacterController.Inventory.InventoryBase.SpawnCharacterItem (Opsive.UltimateCharacterController.Items.CharacterItem characterItemPrefab, Opsive.Shared.Inventory.IItemIdentifier itemIdentifier) (at Assets/Opsive/UltimateCharacterController/Scripts/Inventory/InventoryBase.cs:870)

Opsive.UltimateCharacterController.Inventory.InventoryBase.SpawnItemIdentifiersCharacterItem (Opsive.Shared.Inventory.IItemIdentifier itemIdentifier, System.Int32 addToSlotID) (at Assets/Opsive/UltimateCharacterController/Scripts/Inventory/InventoryBase.cs:780)

Opsive.UltimateCharacterController.Inventory.InventoryBase.AddItemIdentifierAmount (Opsive.Shared.Inventory.IItemIdentifier itemIdentifier, System.Int32 amount, System.Boolean spawnCharacterItems, System.Int32 slotID) (at Assets/Opsive/UltimateCharacterController/Scripts/Inventory/InventoryBase.cs:590)

Opsive.UltimateCharacterController.Inventory.InventoryBase.PickupItem (Opsive.Shared.Inventory.IItemIdentifier itemIdentifier, System.Int32 slotID, System.Int32 amount, System.Boolean immediatePickup, System.Boolean forceEquip, System.Boolean notifyOnPickup, System.Boolean spawnCharacterItems) (at Assets/Opsive/UltimateCharacterController/Scripts/Inventory/InventoryBase.cs:641)

Opsive.UltimateCharacterController.Inventory.InventoryBase.AddItemIdentifierAmount (Opsive.Shared.Inventory.IItemIdentifier itemIdentifier, System.Int32 amount) (at Assets/Opsive/UltimateCharacterController/Scripts/Inventory/InventoryBase.cs:562)

Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem.CharacterInventoryBridge.OnAddItemToInventory (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo itemInfo, Opsive.UltimateInventorySystem.Core.DataStructures.ItemStack addedItemStack) (at Assets/Opsive/UltimateCharacterController/Integrations/UltimateInventorySystem/Scripts/CharacterInventoryBridge.cs:400)

Opsive.Shared.Events.InvokableAction`2[T1,T2].Invoke (T1 arg1, T2 arg2) (at <52329c5bb9d24a17aa3c9cbeab267298>:0)

Opsive.Shared.Events.EventHandler.ExecuteEvent[T1,T2] (System.Object obj, System.String eventName, T1 arg1, T2 arg2) (at <52329c5bb9d24a17aa3c9cbeab267298>:0)

Opsive.UltimateInventorySystem.Core.InventoryCollections.ItemCollection.NotifyAdd (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo itemInfo, Opsive.UltimateInventorySystem.Core.DataStructures.ItemStack addedItemStack) (at Assets/Opsive/UltimateInventorySystem/Scripts/Core/InventoryCollections/ItemCollection.cs:477)

Opsive.UltimateInventorySystem.Core.InventoryCollections.ItemSlotCollection.SetItemAmount (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo itemInfo, System.Int32 slotIndex, System.Boolean removePreviousItem) (at Assets/Opsive/UltimateInventorySystem/Scripts/Core/InventoryCollections/ItemSlotCollection.cs:300)

Opsive.UltimateInventorySystem.Core.InventoryCollections.ItemSlotCollection.AddItemInternal (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo itemInfo, System.Int32 slotIndex) (at Assets/Opsive/UltimateInventorySystem/Scripts/Core/InventoryCollections/ItemSlotCollection.cs:250)

Opsive.UltimateInventorySystem.Core.InventoryCollections.ItemSlotCollection.AddItem (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo itemInfo, System.Int32 slotIndex) (at Assets/Opsive/UltimateInventorySystem/Scripts/Core/InventoryCollections/ItemSlotCollection.cs:216)

Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem.CharacterInventoryBridge.MoveItemToEquippable (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo itemInfo, System.Int32 equippableCollectionIndex, System.Int32 slotIndex) (at Assets/Opsive/UltimateCharacterController/Integrations/UltimateInventorySystem/Scripts/CharacterInventoryBridge.cs:940)

Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem.CharacterInventoryBridge.MoveEquip (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo itemInfo, System.Int32 equippableItemCollectionSet, System.Int32 slotID, System.Boolean equip) (at Assets/Opsive/UltimateCharacterController/Integrations/UltimateInventorySystem/Scripts/CharacterInventoryBridge.cs:1020)

Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem.CharacterInventoryBridge.MoveEquip (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo itemInfo, System.Boolean equip) (at Assets/Opsive/UltimateCharacterController/Integrations/UltimateInventorySystem/Scripts/CharacterInventoryBridge.cs:1007)

Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem.CharacterEquipUnequipItemAction.InvokeActionInternal (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo itemInfo, Opsive.UltimateInventorySystem.ItemActions.ItemUser itemUser) (at Assets/Opsive/UltimateCharacterController/Integrations/UltimateInventorySystem/Scripts/InventoryItemActions/CharacterEquipUnequipItemAction.cs:91)

Opsive.UltimateInventorySystem.ItemActions.ItemAction.InvokeAction (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo itemInfo, Opsive.UltimateInventorySystem.ItemActions.ItemUser itemUser) (at Assets/Opsive/UltimateInventorySystem/Scripts/ItemActions/ItemAction.cs:97)

Opsive.UltimateInventorySystem.UI.Panels.ActionPanels.ItemActionPanel.InvokeActionInternal (System.Int32 index) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/ActionPanels/ItemActionPanel.cs:84)

Opsive.UltimateInventorySystem.UI.Panels.ActionPanels.ActionPanel`1[T].InvokeAction (System.Int32 index) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/ActionPanels/ActionPanel.cs:129)

Opsive.UltimateInventorySystem.UI.Panels.ActionPanels.ActionPanel`1+<>c__DisplayClass18_0[T].<OpenInternal>b__0 () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/ActionPanels/ActionPanel.cs:77)

Opsive.UltimateInventorySystem.UI.CompoundElements.ActionButton.Press () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/CompoundElements/ActionButton.cs:88)

Opsive.UltimateInventorySystem.UI.CompoundElements.ActionButton.OnSubmit (UnityEngine.EventSystems.BaseEventData eventData) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/CompoundElements/ActionButton.cs:273)

UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.ISubmitHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at ./Library/PackageCache/com.unity.ugui@2.0.0/Runtime/UGUI/EventSystem/ExecuteEvents.cs:134)

UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at ./Library/PackageCache/com.unity.ugui@2.0.0/Runtime/UGUI/EventSystem/ExecuteEvents.cs:272)

UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)

Rewired.Integration.UnityUI.RewiredStandaloneInputModule:SendSubmitEventToSelectedObject() (at Assets/Rewired/Integration/UnityUI/RewiredStandaloneInputModule.cs:821)

Rewired.Integration.UnityUI.RewiredStandaloneInputModule:Process() (at Assets/Rewired/Integration/UnityUI/RewiredStandaloneInputModule.cs:676)

UnityEngine.EventSystems.EventSystem:Update()

Rewired.Integration.UnityUI.RewiredEventSystem:Update() (at Assets/Rewired/Integration/UnityUI/RewiredEventSystem.cs:40)
 
Thanks,
So looking at the error, it seems it's coming from the InventoryAmmoDataClip.
Looking at the code it seems the SetAmmoData is called before the Initialize function. And that's the thing causing the issue.

As too why it is being called before intialize, apparently it's because of an AttributeBinding.
I think it's this:
1715069488095.png

Can you check how your prefab compares to the demo ones here?

If for some reason you need a binding and you thing it shouldn't give you an error adding one, I can note this as a bug.

On line 134 of InventoryAmmoDataClip , I've added a null check in case the item action is not initialized. This should fix the error even if you keep a binding (although I'm pretty sure you don't need it)
Code:
if (refreshAmmoList && m_ClipRemaining != null) {

I hope that fixes it for you
 
Top