Ammo in clip displays 0 when item unequipped

BrettL

Member
When the weapon is equipped, it shows the clip ammo and total ammo correctly:
1651261555812.png

However, when I unequip the weapon, the ammo in the clip shows 0, despite it still being in the pistol (it goes back to 12 if I equip it again).
1651261657141.png
The clip size is consistent in the item's "ShootableWeapon" component and the item definition. It fires and reloads correctly. Finally, I don't see any difference in the "WeaponAmmoItemViewModule" component of main grid view slot and the equipped view slot, so I'm not sure what's causing the discrepancy. I would prefer to not have to upgrade, since I've made some modifications to the code base. Let me know if you have any thoughts on where this issue might be stemming from. Thanks for your help!
 
When the weapon is equipped the "WeaponAmmoItemViewModule" checks for the clip ammo on the UCC Item component.
When it is unequipped it checks for the ammo in the AmmoData Attribute.
So either your AmmoData isn't hookedup properly to your Item Component with the WeaponAmmoDataBinding componetn or the "WeaponAmmoItemViewModule" isn't checking the correct spot when the weapon is unequipped.
Are you using a very old version of the integration? (The version can be found in the Integration editor window)
 
Hi Sangemdoko, thanks for your quick reply. I'm using UIS 1.2.5 and UCC 2.4.5, so not the latest, but I would really prefer to not upgrade at this point. I'm not seeing WeaponAmmoDataBinding in this version, but I do see ShootableWeaponAmmoBinding, which I think may be the issue. I found that the "Shootable Weapon" attribute wasn't set on that component, so I set it to the weapon Gameobject (itself). However, after saving the prefab, it still isn't working correctly. I'm wondering if in addition to saving it, I need to somehow rebind it to the inventory? The Ammo Data attribute appears to be correctly set on both the weapon prefab and WeaponAmmoItemViewModule. Thanks again. Here are some screenshots:

1651516953115.png1651516817840.png
 
P.S. I'm not sure if this could be a related issue with some binding not being set up correctly, but when I drag and drop the weapon to equip it, it doesn't equip it on the UCC character. However, If I select "Equip" from the drop-down after clicking on the item, it does equip it on the character. In both cases, it updates the Inventory component on the character, so it's odd that it doesn't actually equip it in the drag and drop case.
 
So I think I made some progress with this. I realized that the ItemBinding was set to the wrong item category, so I changed that and added the AmmoData binding. This changed the behavior, but it's still not quite right. When I equip the weapon the first time, it eats up a full clip of bullets, going from 0/25 to 0/13. However, if I reload or unequip and re-equip, it goes to 12/1 and stays that way. In other words, the first equip eats up 12 bullets that should be loaded into the gun, but subsequent equips work correctly. Screenshots:

1651520050555.png1651520005756.png
 
Sorry it's not "WeaponAmmoDataBinding" it is "ShootableWeaponAmmoBinding" I remembered the name incorrectly. So that's not the issue.

I tried it out in the integration demo scene because it seemed odd. Turns out I have the same problem you do (The first one where it shows 0).

But the problem didn't seem to affect the assault rifle, only the pistol.

Turns out it was an odd bug. The AmmoData was never being bound to the Item because the Pistol didn't have an ItemObject before it was spawned.

So without changing anything from what you had at the beginning you can fix the problem simply by adding an ItemObject component on the prefab.

Just to be safe I added this line of code in the ShootableWeaponAmmoBinding script such that it works even if the ItemObject component isn't preadded.
Code:
/// <summary>
/// On Start double check that the ItemObject is set.
/// </summary>
private void Start()
{
    // Try setting the ItemObject again in case it was added procedurally after awake.
    if (m_ItemObject == null) {
        var itemObject = GetComponent<ItemObject>();
        if (itemObject != null) {
            SetItemObject(itemObject);
        }
    }
}

This could have been easily avoided if I had set the event on the gameobject instead of the component. So I'll add that to my list of things to review for a potential refactor.
 
Nice, it looks like that fixed it, even after the other changes I made! Thanks for taking a deep dive and testing this out in the Demo.

It looks like my issue with dragging and dropping items to equip them still isn't working, so that must be a separate issue. Should I create a new forum post for that? Maybe others have also experienced this drag and drop issue, since I see it's not working in the integration demo either.
 
The drag & drop thing is not a bug.
There are two equip states, active equip and soft equipped.

Soft equip is when the item is part of the character but is not in the active ItemSet.

When you drag&drop you soft equip the item because you simply move it to the Equippable collection.
When you use the equip item action you are actually using a Integration item action called CharacterEquipUnequipItemAction (or something around those lines I don't have the project in front of me)

So if you wish to change what happens on drag and drop you would need to DropAction that uses that ItemAction instead of the default SmartExchange.
There might be a setting on the InventoryBridge to auto active new items but I don't remember if I actually added that or not.
I hope that makes sense
 
I think that makes sense, although I'm still not sure how exactly to trigger the equip action instead of, or in addition to SmartExchange. I'm not seeing a setting on InventoryBridge to auto activate items when soft equipped.
 
Last edited:
That should do the trick. I'd recommend adding a condition just in case you end up having other equipment slots container, but for now you don't have to
 
This appears to be working, let me know if you see any issues with it:

View attachment 8740
Sorry to post on an older thread, but hopefully its contents will save some explanation. I seem to be having some issues with this approach (see attached image) after all. It works in most cases, but it doesn't always work when an item is already equipped and I drag another item into that slot. Instead of unequipping the current item and equipping the dragged item, it plays the animation to equip the first item listed under the item set rules for Equippable. This means that it works when the first item listed is the dragged item, but it doesn't work otherwise.

In contrast, when I trigger the "CharacterEquipUnequipItemAction" via the drop down by clicking on the item, it unequips the old item and equips the new item on the character correctly. I find this odd because the drag and drop is triggering the same action.

I tried to debug the code and my main finding was that the action code is run once for drag and drop, but twice for the drop down selection of the action. Is this because it's being run once on the currently equipped item to unequip that, and then once on the "to be equipped" item? Whereas drag and drop (as implemented above) is running it once on the first index of the item set rules that matches an item in the inventory?

Is there a way to change my above implementation to trigger the item action on the correct item/items so that it works the same as the drop down implementation?
 
I'm not sure why this helped, but I unchecked "Can Switch To" on the "Melee Body" item under the "Body" item set rule, and now it appears to be working. I'm not sure if "Body" was some kind of transition state or what was happening, but I'll try to test this out some more and see if it's a long term solution. I do have "Melee Body" in my character's inventory.
 
Top