How To Drop Unequippable Item As ItemPickup

SteveC

Member
Hey y'all =)

Is there an expected way to drop unequippable items as an ItemPickup (eg. drop 10 pistol bullets)?

I'm using AdjustItemIdentifierAmount to drop unequippable items and that's working great. It'd be nice for the Player to be able to drop the ammo as an ItemPickup, currently it simply removes the specified amount (using a slider between 1 and current item count).

If I have a reference to a Drop and/or ItemPickup prefab, is there a preferred way to:

1. Drop the item as an ItemPickup
2. Set the ItemIdentifier and amount on the ItemPickup

Thanks much
 
Last edited:
Take a look at the "Drop Script" on this page:


RemoveItem() should be what you are looking for.

Although if you want the player to be able to only drop some of the bullets and not all of them, you'll need to do something different. You could try adding your own simple script which reduces the ammo amount by X and spawns a game object with the ItemPickup component, with its amount equal to X.
 
Thanks for the reply!

I'm using RemoveItem() to remove equippable items, but RemoveItem requires a Slot and doesn;t take an amount so I've had to differentiate the two (using a UIItemCategory enum) and use AdjustItemIdentifierAmount.

Here's how I'm using them:

C#:
/// <summary>
    /// If we have an ItemCategory=Equippable, we wanna RemoveItem so it's dropped
    /// If we have an ItemCategory=Unequippable, we need to AdjustItemIDAmount
    /// TODO: how to manually drop the Item?
    /// </summary>
    /// <param name="inventoryObject"></param>
    /// <param name="amount"></param>
    public void DropItems(InventoryObject inventoryObject, int amount)
    {
        IItemIdentifier itemIdentifier = inventoryObject.m_ItemID;
        UIItemInfo itemInfo = inventoryObject.m_ItemInfo;

        if (itemInfo.ItemCategory == UIItemCategory.Equippable)
        {
            PlayerInventoryManager.Instance.m_InventoryBase.RemoveItem(itemIdentifier, 0, true);
        }

        if (itemInfo.ItemCategory == UIItemCategory.Unequippable)
        {
            PlayerInventoryManager.Instance.m_InventoryBase.AdjustItemIdentifierAmount(itemIdentifier, -amount);
        }
    }

I tried just adding the ammo as an Item that couldn;t be switched to, but again ran into that RemoveItem doesn;t take an amount.

I had the same idea to manually drop the item, but I'm unsure what the best way to do that is.

Y'know if there's an expected way to handle this scenario outside of manually spawning a PickupItem and tossing it?

And if that's the case, and ideas on a good way to spawn and toss it?

I have a few but I'm unsure how to use an ItemPickup for this so I think I'll hit up:

Thanks much =)
 
Last edited:
The ItemPickup component is pretty straightforward to set up for a simple ammo pickup. Something like this:

1590668668531.png

You should also be able to adjust the Amount value during run-time by accessing the ItemPickup script and modifying the ItemDefinition.amount value, ie. ItemDefinitionAmounts[0].value = X.
 
Thanks for the reply!

Here was my working test @ setting the ItemPickup script:

C#:
/// <summary>
    /// If we have an ItemCategory=Equippable, we wanna RemoveItem so it's dropped
    /// If we have an ItemCategory=Unequippable, we need to AdjustItemIDAmount
    /// </summary>
    /// <param name="inventoryObject">ItemID+ItemInfo</param>
    /// <param name="amount">Amount to modify</param>
    public void DropItems(InventoryObject inventoryObject, int amount)
    {
        IItemIdentifier itemIdentifier = inventoryObject.m_ItemID;
        UIItemInfo itemInfo = inventoryObject.m_ItemInfo;

        if (itemInfo.ItemCategory == UIItemCategory.Equippable)
        {
            PlayerInventoryManager.Instance.m_InventoryBase.RemoveItem(itemIdentifier, 0, true);
        }

        if (itemInfo.ItemCategory == UIItemCategory.Unequippable)
        {
            PlayerInventoryManager.Instance.m_InventoryBase.AdjustItemIdentifierAmount(itemIdentifier, -amount);

            if (itemInfo.DropItem != null) { DropPickupItem(inventoryObject, amount); }
        }
    }

    /// <summary>
    /// Manually drop our pickup item.  Sets the PickupItem's ItemIdentifier and amount
    /// TODO: Having trouble with using ItemPlacement, per ItemPickupBase
    /// </summary>
    /// <param name="inventoryObject">ItemID+ItemInfo</param>
    /// <param name="amount">Amount to modify</param>
    public void DropPickupItem(InventoryObject inventoryObject, int amount)
    {
        IItemIdentifier itemIdentifier = inventoryObject.m_ItemID;
        UIItemInfo itemInfo = inventoryObject.m_ItemInfo;

        GameObject instantiatedObject = GameObject.Instantiate(itemInfo.DropItem, m_Character.transform.position + m_ItemDropOffset, m_Character.transform.rotation, m_DropParent.transform);
        ItemPickupBase itemPickup = instantiatedObject.GetComponent<ItemPickup>();

        ItemDefinitionAmount[] itemDefinitionAmountAsArray = new ItemDefinitionAmount[] { new ItemDefinitionAmount(itemIdentifier.GetItemDefinition(), amount) };

        itemPickup.SetItemDefinitionAmounts(itemDefinitionAmountAsArray);
        itemPickup.PickupOnTriggerEnter = false;
        itemPickup.TriggerEnableDelay = 4.0f;
    }

TrajectoryObject's giving me some troubles, the item clearly spawns and immediately gets picked up.

I've set the ItemPickup to not pick the item up on trigger (PickupOnTriggerEnter=FALSE) and set the Trigger delay to 4.0.

No dice.

Any ideas on what I might be doing wrong there?
 
Last edited:
I'm actually not sure what's causing the ItemPickup to still get triggered in that case. You could try having the ItemPickup component itself disabled by default and only enable it once the object has collided with a surface or after X amount of time.
 
Wrote a script to control when ItemPickup gets enabled... then realized maybe I should check the PickupItem ability...

Had the ItemPickup Ability StartType as Automatic.

Switching ItemPickup to StartType=ButtonDown fixed the issue =)
 
Ok the conclusion minus a lotta details was:

For dropping unequippable items from the inventory, used AdjustItemIdentifierAmount to change the Inventory amount, made a non-visible Item out of it (nothing but an Item script with a Drop prefab):

1591027477386.png


...made a custom Drop function (DropWithItemAndAmount) in the Item script and added a Drop Ability to the Character controller that's StartType=Manual. Then we call Item.DropWithItemAndAmount to drop the item.

DropWithItemAndAmount is just a stripped down Drop(bool), since I don;t need to do any getting or checking of items, though I did hafta make my own DropPoint for items to drop from.

The problem with things automatically picking up even though the ItemPickup had PickupOnTriggerEnter=FALSE was to fix the ItemPickup ability to be StartType=ButtonDown

The problem with TrajectoryObject was resolved by correctly using TrajectoryObject.Initialize(). Until this' called the object doesn't activate this component, and I got no results from InitializeOnAwake=TRUE.
 
Last edited:
Top