Random Item Pickup with Ultimate Inventory

RobotGames

Member
I am using Ultimate Inventory and would like something like RandomInventoryPickup available in the integration. Like I pick up a clip of bullets and it could be in a range of 2-12 bullets. I started looking at injecting a random count but so far I have just started.
 
It is true that I added a random drop but did not add a random pickup. I'll add it to my todo list.
1598358683212.png

We just released version 1.0.5 today so it may take a while before the update with that new feature.

If your use case works for it feel free to use the random Item dropper.

If that does not work for your use case I would create a new script that inherits the integration InventoryItemPickupcomponent and override the "DoItemIdentifierPickupInternal" function:
1598358973004.png

You can multiply the item amount, underlined in red in the image above, by a random value (i.e 50%-150%). This should work out quite well.

The itemAmount.Amount underlined in red is the amount specified in the inventory that sits next to the InventoryItemPickup.

I hope that helps
 
Yea I looked at it and went with the inherited component, like I said I was trying with the injection. What I do not understand is the random item dropper, specifically the InventoryPickupIntegration in the pickup prefab?
 
The InventoryPickupIntegration prefab uses the UIS way for interaction/pickup.

It has an interactable component which you character can interact with if it has an InventoryInteractor component.

The random item dropper spawns a pickup (itemPickup or inventoryPickup) depending on the prefab you give him. If it's an inventory prefab, I assign all the items to drop to the instantiated pickup in its inventory.
If it's an ItemPickup I instantiate the prefab for each item I am dropping.

Does this clear up some misunderstandings?
 
The InventoryPickupIntegration prefab uses the UIS way for interaction/pickup.

It has an interactable component which you character can interact with if it has an InventoryInteractor component.

The random item dropper spawns a pickup (itemPickup or inventoryPickup) depending on the prefab you give him. If it's an inventory prefab, I assign all the items to drop to the instantiated pickup in its inventory.
If it's an ItemPickup I instantiate the prefab for each item I am dropping.

Does this clear up some misunderstandings?

No It does not exist. What is it? Where is it? How is it created?
 
I'm sorry, what does not exist?

The InventoryInteractor component is a component that is set on the character game object next to the UIS/UCC bridge component.

InventoryPickupIntegration is a prefab you can find in the demo folders, you can duplicate it to make your own.

If you are still having issues could write in detail what you wish to achieve, I'll try to guide you the best I can
 
I wrote my own by inheriting from InventoryItemPickup. What I am saying is I cannot get your example to work there is no prefab named InventoryPickupIntegration unless you have changed something. Is it the InventoryPickup in the demo folder? I did a search for InventoryPickupIntegration and nothing is found.


Capture.JPG
 
Hi @RobotGames , I'm very sorry I read back your first post and you mentioned you were using the "Integration" which I assumed to be the UCC/UIS integration since you posted this thread in the UIS/UCC integration category.

Could you confirm which integration you are using?

If you are indeed using UCC/UIS together and downloaded the integration package you should be seeing the InventoryPickupIntegration here
1598857768854.png
If for what ever reason it is not there, try selecting the Random item dropper in the UCC/UIS integration demo and check the Pickup Prefab field on the Random Item Dropper component.
1598858515316.png

If you are not using the UCC integration, but something else (BD, Play Maker integration), then you should be able to use the default Random Inventory Pickup. It can't be used for the UCC integration as the pickup process is slightly different.

1598858045759.png
 
We'll be adding a new version for the integration soon. Here is the code for the RandomInventoryItemPickup you requested, it will be part of the next update:

C#:
    public class RandomInventoryItemPickup : InventoryItemPickup
    {
        [Tooltip("The minimum amount of item that can be picked up.")]
        [SerializeField] protected int m_MinAmount = 1;
        [Tooltip("The maximum amount of item that can be picked up.")]
        [SerializeField] protected int m_MaxAmount = 2;

        protected ItemAmountProbabilityTable m_ItemAmountProbabilityTable;

        /// <summary>
        /// Initialize the probability table.
        /// </summary>
        protected virtual void Start()
        {
            m_ItemAmountProbabilityTable = new ItemAmountProbabilityTable((m_Inventory.MainItemCollection.GetAllItemStacks(), 0));
        }
        
        /// <summary>
        /// Internal method which picks up the ItemIdentifier.
        /// </summary>
        /// <param name="character">The character that should pick up the ItemIdentifier.</param>
        /// <param name="inventory">The inventory belonging to the character.</param>
        /// <param name="slotID">The slot ID that picked up the item. A -1 value will indicate no specified slot.</param>
        /// <param name="immediatePickup">Should the item be picked up immediately?</param>
        /// <param name="forceEquip">Should the item be force equipped?</param>
        /// <returns>True if an ItemIdentifier was picked up.</returns>
        protected override bool DoItemIdentifierPickupInternal(GameObject character, InventoryBase inventory, int slotID, bool immediatePickup, bool forceEquip)
        {
            if (m_ItemAmountProbabilityTable.Count == 0) { return false; }
            
            var pickupItems = m_ItemAmountProbabilityTable.GetRandomItemAmounts(m_MinAmount, m_MaxAmount);
            
            var inventorySystemInventory = character.GetCachedComponent<Inventory>();
            for (int i = 0; i < pickupItems.Count; ++i) {
                var itemAmount = pickupItems[i];
                if (itemAmount.Item.IsMutable) {
                    inventorySystemInventory.MainItemCollection.AddItem(InventorySystemManager.CreateItem(itemAmount.Item, null), itemAmount.Amount);
                } else {
                    inventorySystemInventory.MainItemCollection.AddItem(itemAmount.Item, itemAmount.Amount);
                }
            }
            return pickupItems.Count > 0;
        }
    }
 
Do you have any detailed steps for this?

I have replicated the "Random Item Dropper" (from ucc integration). The randoms are spawned, however I can not pick them up.
 
there are a few things to check when you can't seem to pickup an item.
1) Make sure you've either set an input to pickup (either on the Inventory Interactor component or the Pickup Ability depending on the Item Pickup you are using) or that you've set to pickup automatically on trigger enter
2) Make sure that the layer mask of the pickup/interactable contains the player layer

Double check the documentation to see if you are missing anything
 
there are a few things to check when you can't seem to pickup an item.
1) Make sure you've either set an input to pickup (either on the Inventory Interactor component or the Pickup Ability depending on the Item Pickup you are using) or that you've set to pickup automatically on trigger enter
2) Make sure that the layer mask of the pickup/interactable contains the player layer

Double check the documentation to see if you are missing anything
Thanks, it was for some reason not setting auto interact, so that solved the issue. Some other minor things todo, but should be able to figure them out through the demo.
 
Top