Ammo pickup emptys weapon clip

Zaddo

Active member
I have a custom item pickup inherting from pickupBase. When I pick up ammo, the ammo in the weapon clip is removed and added to the ammo stack. It doesn't matter if the gun is just in the inventory or held by the player. I have linked a short video to show what is happening.

The only other post I found that might be related is this one, but I don't think it is the same issue: https://opsive.com/forum/index.php?threads/ammo-inventory-weirdness-ucc-2-3-5-uis-1-1-8.6276/

Here is the code:

C#:
        protected virtual bool AddPickupToCollection(ItemCollection itemCollection)
        {
            Core.DataStructures.ItemInfo itemInfo;
            bool success = false;

            var pickupItems = m_Inventory.MainItemCollection.GetAllItemStacks();
            if (pickupItems.Count > 1)
            {
                Debug.LogWarning("InventoryShapGridPickup can only pickup one item at a time");
                return false;
            }
            Shared.Events.EventHandler.ExecuteEvent(m_Inventory.gameObject, "OnItemPickupStartPickup");
            for (int i = 0; i < pickupItems.Count; i++)
            {
                var itemAmount = pickupItems[i];
                if (itemAmount.Item.IsMutable)
                {
                    itemInfo = itemCollection.AddItem(Item.Create(itemAmount.Item), itemAmount.Amount);
                }
                else
                {
                    itemInfo = itemCollection.AddItem(itemAmount.Item, itemAmount.Amount);
                }

                // Update server if we were successful
                success = itemInfo.Amount > 0;

            }
            Shared.Events.EventHandler.ExecuteEvent(m_Inventory.gameObject, "OnItemPickupStopPickup");

            if (success)
            {
                // Notify server we have picked up item
                PlaySound();
            }
            else
                PlaySoundFail();

            return success;
        }
 
Last edited:
That's odd. Your code looks perfectly ok.
Are you able to replicate this bug in the integration demo scene?
I tried to replicate it in my development project but everything seems to work fine.

Can you double check your Inventory System version?

That being said I did make some changes to things that had to do with ammo since the last update, so its possible that this issue is fixed in my project. We don't have an update scheduled soon because we made some big changes (related to the sound manager) and we need to syncrhonise the UCC 2.4 update with the UIS 1.2 update because of the shared folders. We are hoping to have the update ready at the end of the month.

If you are in a hurry and cannot way for the update, one way you could try to debug this issue is by adding Debug.Logs inside the "Shootable Weapon Ammo Binding" component. That should give us an idea of why the ammo remaining is set to 0.
 
I couldn't reproduce the issue in the demo scene. I added my pickup system and the Itemcollection.additem call worked faultlessly. There must be some setup difference in my project.

My versions are: UIS 1.1.8 UCC 2.3.5

I can fix the problem by turning off automatic reload on the weapons. I think there might be a bug here. I found this after a few hours of debugging. I don't think I want auto-reload in my game, so I am happy just to turn it off. But if you think it is a bug and you want any more information, let me know, I am to gather more info if it helps.

I put breakpoints and debugs in the ShootableWeaponAmmoBinding, but they did not capture the value changing to Zero. I expected this to happen in the AmmoData setter, but this code did not run?

What I found is that the pickup of the ammo, triggers the weapon to reload, which empties the clip, see the screen capture setting the clip quantity to zero with a negative reload amount. Cutting out a few steps this is what happens:

ItemCollection.AddInternal calls NotifyAdd
NotifyAdd Raise Event ==> c_Inventory_OnAdd_ItemInfo_ItemStack
CharacterInventoryBridge.OnAddItemToInventory
InventoryBase.ItemIdentifierPickedUp ==> Raise Event "OnInventoryPickupItemIdentifier"
Reload.OnPickupItemIdentifier is THen called
Reload.ReloadItem (See Screen Capture) Adjust clip to zero
Call Event => c_Inventory_OnAdd_ItemInfo_ItemStack **** Gets Called a second time, this is why in video you see two stacks of ammo appearing in the monitor

1631098835957.png

Here is the full call stack:
Code:
Void Opsive.UltimateInventorySystem.UI.Monitors.InventoryMonitor:OnItemAmountAdded (ItemInfo, ItemStack)+0x1 at G:\UnityProjects\DeadFear2\DeadFear2\Assets\Opsive\UltimateInventorySystem\Scripts\UI\Monitors\InventoryMonitor.cs:[256:13-256:34]    C#
     Void Opsive.Shared.Events.InvokableAction`2:Invoke (ItemInfo, ItemStack)+0x8 at :-1    C#
     Void Opsive.Shared.Events.EventHandler:ExecuteEvent (Object, String, ItemInfo, ItemStack)+0x2a at :-1    C#
     Void Opsive.UltimateInventorySystem.Core.InventoryCollections.ItemCollection:NotifyAdd (ItemInfo, ItemStack)+0x23 at G:\UnityProjects\DeadFear2\DeadFear2\Assets\Opsive\UltimateInventorySystem\Scripts\Core\InventoryCollections\ItemCollection.cs:[429:17-431:47]    C#
     ItemInfo Opsive.UltimateInventorySystem.Core.InventoryCollections.ItemCollection:AddInternal (ItemInfo, ItemStack, Boolean)+0x143 at G:\UnityProjects\DeadFear2\DeadFear2\Assets\Opsive\UltimateInventorySystem\Scripts\Core\InventoryCollections\ItemCollection.cs:[412:30-412:66]    C#
     ItemInfo Opsive.UltimateInventorySystem.Core.InventoryCollections.ItemCollection:AddItem (ItemInfo, ItemStack)+0x7f at G:\UnityProjects\DeadFear2\DeadFear2\Assets\Opsive\UltimateInventorySystem\Scripts\Core\InventoryCollections\ItemCollection.cs:[494:50-494:108]    C#
     ItemInfo Opsive.UltimateInventorySystem.Core.InventoryCollections.ItemCollection:AddItem (Item, Int32)+0xf at G:\UnityProjects\DeadFear2\DeadFear2\Assets\Opsive\UltimateInventorySystem\Scripts\Core\InventoryCollections\ItemCollection.cs:[511:13-511:54]    C#
     Void Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem.CharacterInventoryBridge:AdjustItemIdentifierAmountInternal (IItemIdentifier, Int32)+0x109 at G:\UnityProjects\DeadFear2\DeadFear2\Assets\Opsive\UltimateCharacterController\Integrations\UltimateInventorySystem\Scripts\CharacterInventoryBridge.cs:[873:21-873:67]    C#
     Void Opsive.UltimateCharacterController.Inventory.InventoryBase:AdjustItemIdentifierAmount (IItemIdentifier, Int32)+0x15 at
 
Last edited:
stack was too big. Here is the rest of it:
Code:
G:\UnityProjects\DeadFear2\DeadFear2\Assets\Opsive\UltimateCharacterController\Scripts\Inventory\InventoryBase.cs:[473:13-473:72]    C#

     Void Opsive.UltimateCharacterController.Items.Actions.ShootableWeapon:ReloadItem (Boolean)+0x18c at G:\UnityProjects\DeadFear2\DeadFear2\Assets\Opsive\UltimateCharacterController\Scripts\Items\Actions\ShootableWeapon.cs:[1576:13-1576:95]    C#

>    Void Opsive.UltimateCharacterController.Character.Abilities.Items.Reload:OnTryReload (Int32, IItemIdentifier, Boolean, Boolean)+0x121 at G:\UnityProjects\DeadFear2\DeadFear2\Assets\Opsive\UltimateCharacterController\Scripts\Character\Abilities\Items\Reload.cs:[553:25-553:57]    C#

     Void Opsive.UltimateCharacterController.Character.Abilities.Items.Reload:OnPickupItemIdentifier (IItemIdentifier, Int32, Boolean, Boolean)+0x6 at G:\UnityProjects\DeadFear2\DeadFear2\Assets\Opsive\UltimateCharacterController\Scripts\Character\Abilities\Items\Reload.cs:[511:13-511:68]    C#

     Void Opsive.Shared.Events.InvokableAction`4:Invoke (IItemIdentifier, Int32, Boolean, Boolean)+0xb at :-1    C#

     Void Opsive.Shared.Events.EventHandler:ExecuteEvent (Object, String, IItemIdentifier, Int32, Boolean, Boolean)+0x2e at :-1    C#

     Void Opsive.UltimateCharacterController.Inventory.InventoryBase:ItemIdentifierPickedUp (IItemIdentifier, Int32, Int32, Boolean, Boolean)+0x46 at G:\UnityProjects\DeadFear2\DeadFear2\Assets\Opsive\UltimateCharacterController\Scripts\Inventory\InventoryBase.cs:[268:13-268:141]    C#

     Void Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem.CharacterInventoryBridge:OnAddItemToInventory (ItemInfo, ItemStack)+0x55 at G:\UnityProjects\DeadFear2\DeadFear2\Assets\Opsive\UltimateCharacterController\Integrations\UltimateInventorySystem\Scripts\CharacterInventoryBridge.cs:[241:21-241:93]    C#

     Void Opsive.Shared.Events.InvokableAction`2:Invoke (ItemInfo, ItemStack)+0x8 at :-1    C#

     Void Opsive.Shared.Events.EventHandler:ExecuteEvent (Object, String, ItemInfo, ItemStack)+0x2a at :-1    C#

     Void Opsive.UltimateInventorySystem.Core.InventoryCollections.ItemCollection:NotifyAdd (ItemInfo, ItemStack)+0x23 at G:\UnityProjects\DeadFear2\DeadFear2\Assets\Opsive\UltimateInventorySystem\Scripts\Core\InventoryCollections\ItemCollection.cs:[429:17-431:47]    C#

     ItemInfo Opsive.UltimateInventorySystem.Core.InventoryCollections.ItemCollection:AddInternal (ItemInfo, ItemStack, Boolean)+0x143 at G:\UnityProjects\DeadFear2\DeadFear2\Assets\Opsive\UltimateInventorySystem\Scripts\Core\InventoryCollections\ItemCollection.cs:[412:30-412:66]    C#

     ItemInfo Opsive.UltimateInventorySystem.Core.InventoryCollections.ItemCollection:AddItem (ItemInfo, ItemStack)+0x7f at G:\UnityProjects\DeadFear2\DeadFear2\Assets\Opsive\UltimateInventorySystem\Scripts\Core\InventoryCollections\ItemCollection.cs:[494:50-494:108]    C#

     ItemInfo Opsive.UltimateInventorySystem.Core.InventoryCollections.ItemCollection:AddItem (Item, Int32)+0xf at G:\UnityProjects\DeadFear2\DeadFear2\Assets\Opsive\UltimateInventorySystem\Scripts\Core\InventoryCollections\ItemCollection.cs:[511:13-511:54]    C#

     Boolean Opsive.UltimateInventorySystem.DropsAndPickups.InventoryShapeGridPickup:AddPickupToCollection (ItemCollection)+0x9f at G:\UnityProjects\DeadFear2\DeadFear2\Assets\DeadFear\Opsive\UltimateInventorySystem\InventoryShapeGridPickup.cs:[111:21-111:91]    C#

     Void Opsive.UltimateInventorySystem.DropsAndPickups.InventoryShapeGridPickup:OnInteractInternal (IInteractor)+0x22 at G:\UnityProjects\DeadFear2\DeadFear2\Assets\DeadFear\Opsive\UltimateInventorySystem\InventoryShapeGridPickup.cs:[77:13-77:104]    C#

     Void Opsive.UltimateInventorySystem.DropsAndPickups.InventoryShapeGridPickup:OnInteract (IInteractor)+0x3 at G:\UnityProjects\DeadFear2\DeadFear2\Assets\DeadFear\Opsive\UltimateInventorySystem\InventoryShapeGridPickup.cs:[66:13-66:44]    C#

     Void Opsive.Shared.Events.InvokableAction`1:Invoke (IInteractor)+0x7 at :-1    C#

     Void Opsive.Shared.Events.EventHandler:ExecuteEvent (Object, String, IInteractor)+0x29 at :-1    C#

     Boolean Opsive.UltimateInventorySystem.Interactions.Interactable:Interact (IInteractor)+0x2c at G:\UnityProjects\DeadFear2\DeadFear2\Assets\Opsive\UltimateInventorySystem\Scripts\Interactions\Interactable.cs:[172:13-172:126]    C#

     Void Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem.CameraInventoryInteractor:InteractWith (IInteractable)+0x3 at G:\UnityProjects\DeadFear2\DeadFear2\Assets\DeadFear\Client\ScriptsTemp\UIS\CameraInventoryInteractor.cs:[156:13-156:41]    C#

     Void Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem.CameraInventoryInteractor:Interact ()+0x21 at G:\UnityProjects\DeadFear2\DeadFear2\Assets\DeadFear\Client\ScriptsTemp\UIS\CameraInventoryInteractor.cs:[83:17-83:50]    C#

     Void Opsive.Shared.Events.InvokableAction:Invoke ()+0x6 at :-1    C#

     Void Opsive.Shared.Events.EventHandler:ExecuteEvent (String)+0x27 at :-1    C#

     Void DeadFear.Settings.DeadFearGameInputListener:OnAction (CallbackContext)+0x15 at G:\UnityProjects\DeadFear2\DeadFear2\Assets\DeadFear\Client\Settings\DeadFearGameInputListener.cs:[86:17-86:86]    C#

     Void UnityEngine.InputSystem.Utilities.DelegateHelpers:InvokeCallbacksSafe (InlinedArray`1, CallbackContext, String, Object)+0x32 at G:\UnityProjects\DeadFear2\DeadFear2\Library\PackageCache\com.unity.inputsystem@1.0.2\InputSystem\Utilities\DelegateHelpers.cs:[51:21-51:44]    C#

     Void UnityEngine.InputSystem.InputActionState:CallActionListeners (Int32, InputActionMap, InputActionPhase, InlinedArray`1, String)+0xea at G:\UnityProjects\DeadFear2\DeadFear2\Library\PackageCache\com.unity.inputsystem@1.0.2\InputSystem\Actions\InputActionState.cs:[1708:13-1708:95]    C#

     Void UnityEngine.InputSystem.InputActionState:ChangePhaseOfActionInternal (Int32, TriggerState*, InputActionPhase, TriggerState)+0x172 at G:\UnityProjects\DeadFear2\DeadFear2\Library\PackageCache\com.unity.inputsystem@1.0.2\InputSystem\Actions\InputActionState.cs:[1661:21-1661:106]    C#

     Void UnityEngine.InputSystem.InputActionState:ChangePhaseOfAction (InputActionPhase, TriggerState, InputActionPhase)+0x188 at G:\UnityProjects\DeadFear2\DeadFear2\Library\PackageCache\com.unity.inputsystem@1.0.2\InputSystem\Actions\InputActionState.cs:[1604:17-1604:94]    C#

     Void UnityEngine.InputSystem.InputActionState:ProcessDefaultInteraction (TriggerState, Int32)+0xab at G:\UnityProjects\DeadFear2\DeadFear2\Library\PackageCache\com.unity.inputsystem@1.0.2\InputSystem\Actions\InputActionState.cs:[1291:25-1291:85]    C#

     Void UnityEngine.InputSystem.InputActionState:ProcessControlStateChange (Int32, Int32, Int32, Double, InputEventPtr)+0x1c0 at G:\UnityProjects\DeadFear2\DeadFear2\Library\PackageCache\com.unity.inputsystem@1.0.2\InputSystem\Actions\InputActionState.cs:[952:17-952:69]    C#

     Void UnityEngine.InputSystem.InputActionState:UnityEngine.InputSystem.LowLevel.IInputStateChangeMonitor.NotifyControlStateChanged (InputControl, Double, InputEventPtr, Int64)+0x23 at G:\UnityProjects\DeadFear2\DeadFear2\Library\PackageCache\com.unity.inputsystem@1.0.2\InputSystem\Actions\InputActionState.cs:[833:13-833:93]    C#

     Void UnityEngine.InputSystem.InputManager:FireStateChangeNotifications (Int32, Double, InputEvent*)+0x8e at G:\UnityProjects\DeadFear2\DeadFear2\Library\PackageCache\com.unity.inputsystem@1.0.2\InputSystem\InputManager.cs:[2914:21-2915:48]    C#

     Boolean UnityEngine.InputSystem.InputManager:UpdateState (InputDevice, InputUpdateType, Void*, UInt32, UInt32, Double, InputEventPtr)+0x119 at G:\UnityProjects\DeadFear2\DeadFear2\Library\PackageCache\com.unity.inputsystem@1.0.2\InputSystem\InputManager.cs:[3101:17-3101:83]    C#

     Boolean UnityEngine.InputSystem.InputManager:UpdateState (InputDevice, InputEvent*, InputUpdateType)+0x112 at G:\UnityProjects\DeadFear2\DeadFear2\Library\PackageCache\com.unity.inputsystem@1.0.2\InputSystem\InputManager.cs:[3017:13-3018:70]    C#

     Void UnityEngine.InputSystem.InputManager:OnUpdate (InputUpdateType, InputEventBuffer)+0x562 at
 
Thank you for looking into it in such detail. I'll see if I can find anything wrong with the code.
As I mentioned before I did make some changes recently related to ammo, so I might have already fixed this issue.
 
I am embarrassed to let you know, this was my fault. I am just sharing my embarressment in case someone else makes the same mistake and this might help them.

On my Inventory Pickup, I had set the override value for the clipsize to zero.

@Sangemdoko Sorry for wasting your time :(


1631332722903.png
 
Top