AutoReloadType.Pickup not working?

airoll

Member
Hi I'm trying to get AutoReloadType.Pickup to work properly.

Before reading any further, please refer to this thread: https://opsive.com/forum/index.php?threads/autoreloadtype-equip-has-wrong-enum-value.9691/ where it seems like AutoReloadType.Pickup triggers reloading on every Equip, therefore making it seem like it's working on Pickup, but once you fix the enum value of AutoReloadType.Equip it no longer works.

If I pickup a weapon, then this triggers OnPickupItemIdentifier where itemIdentifier is the weapon identifier. However, In Reload.cs, this calls

C#:
OnTryReload(-1, null, itemIdentifier, immediatePickup, true);

This means that the weapon is actually being sent as the ammoItemIdentifier and not the weaponItemIdentifier, which causes subsequent calls to GenericReloader.ShouldReload to fail because the ammoItemIdentifier is the weapon and not the ammo identifier. It never is called where the itemIdentifier is the ammo identifier because in CharacterInventoryBridge.cs and OnAddItemToInventory:

C#:
if (!m_BridgeItemCollections.Contains(destinationItemCollection)) { return; }

causes an early return because my ammo is added to the Default collection which is not in BridgeItemCollections. According to the tooltip, BridgeItemCollections should only contain the equippable item collections. As a result, this doesn't cause base.AddItemIdentifierAmount to trigger, which is responsible for calling InventoryBase.PickupItem, which eventually calls Reload.OnTryReload.

Even if we send the weapon identifier properly as weaponItemIdentifier, then we still don't know what the ammo identifier should be. What's the best way to fix this? I can think of a few:
  1. Add the ammo definition as a property of the ReloaderModule that can be assigned in the editor, and retrieve it from IReloadableItem.ReloadableItemModule.
  2. Add a IAmmoModule interface that has a AmmoItemDefinition, have all AmmoModules implement IAmmoModule, and add AmmoItemModule to IReloadableItem.
  3. Another approach?
Would love to get your recommendation for how to solve this overall problem.
 
Last edited:
Ah I see what you are refering to now ....
I will need to have a better look at this.
unfortunatly I will not have time this week. But I'll try to look at it soon after
 
Thanks! Just as an update here, I tried the approach suggested in my previous post and it did not work because at the time OnTryReload is called, the reloadable item is not yet initialized. I managed to fix this (not saying this generalizes to everyone) by making it so that ammo is always picked up after a weapon, and then adding the following to OnAddItemToInventory in CharacterInventoryBridge (technically I subclassed it but the same principle applies):

C#:
if (m_AmmoCategory.Value.InherentlyContains(itemInfo.Item))
{
    // Send a signal to Reload that ammo has been picked up.
    EventHandler.ExecuteEvent(m_GameObject, "OnInventoryPickupItemIdentifier",
        inventoryItemInfo.Value.Item as IItemIdentifier, itemInfo.Amount, true, false);
}
 
Top