Pickable
A component responbile for handling pickable items.
Last updated
Was this helpful?
A component responbile for handling pickable items.
Last updated
Was this helpful?
The Pickable component is an interactable component responsible for adding the target item to your inventory. The item can be either a collectable or an inventory item:
Collectable items include things like ammo.
Inventory items include firearms, throwables, and other usable items.
When the player interacts with an object that has the Pickable component, it will be added to their inventory according to its type.
To create a new Pickable item, follow these steps:
Create an empty GameObject.
Attach the Pickable component to the GameObject.
Set the layer of this GameObject to "Interactable" to ensure it can be interacted with.
This setup allows the item to be picked up and added to the player's inventory when interacted with.
As shown above, a cube is created for visualization purposes, with the Pickable component attached, the layer set to "Interactable", and a Box Collider added. This setup allows you to visually see the pickable item in the game scene and ensures that it is properly interactable when the player approaches it.
With this setup complete, if you enter play mode and try to interact with the item, you may see a warning message saying "Pickable is inactive or item is null...". This happens because the item is not assigned yet. To fix this, assign an Inventory Item to the "Item To Pickup" field.
The pickable item now is working as intended.
By setting the field "Type" to "Collectable", the inspector of the Pickable component changes as seen below.
As seen above, there are two fields: "Collectable Identifier" and "Amount To Collect".
Collectable Identifier functions as the item to pick up, but specifically for collectables (like ammo).
When the item is picked up, the system searches the inventory for a matching collectable.
If found, it increases the collectable’s Count by the value set in "Amount To Collect".
As seen below, the Inventory has a list called "Collectables", which is what the Collectable Pickable interacts with. When a collectable item is picked up, it searches this list to find a matching identifier and adds the specified amount to it.
This only works if the Collectable Identifier in the Pickable component matches one of the Collectable items in the Inventory's Collectables list. If there's no match, the item won't be added when picked up.
You can assign the firearm you created following the page, any of the default firearms, or throwables. For this example, you can use the default Assault Rifle_1.