World Items
Overview
World Items (ABLWorldItem
) are actor representations of item stacks. They can have visual components that the player may interact with. Players may pick up or drop them to the ground.
The example project provides top-down and third-person styles for world items, although they may also be used for other genres. The way players pick up world items will change depending on your genre. For example:
- Top-Down: Uses a world widget that the player may click on. This isn't viable for games without cursors.
- Third Person / First Person: Uses an 'interaction' system, meaning a periodic trace in the camera's direction focuses on an item. The player may then press a button to pick up the focused item.
Set Up
World Item Class
To start out, create a subclass of ABLWorldItem
. The example map uses the BP_GenericWorldItem
blueprint for this.
You can add custom behavior to item actors here; you will almost always want to override On Item Stack Updated
to change how the world item looks based on its item stack. For example, BP_GenericWorldItem
uses this to change its mesh from the item definition:
Item Definition
In your item definition, set the world item class to the world item class we created above.
Dropping
Once your item definition has a world item class, you can drag the item definition into the world to place world item actors.
If you want to drop items at runtime, use the Try Spawn Item Stack
function, then pass the item stack to Try Drop Items
. Note that these functions will only work on the server.
When a player wants to drop items into the world, use their Inventory Controller. This interface is implemented by two built-in components:
BLInventoryControllerComponent
. A simple implementation for users who aren't using Epic's Gameplay Abilities System.BLInventoryAbilitySystemComponent
. For developers who want to use abilities to manipulate inventories.
Call the RequestDropWorldItem
function to drop items:
By default, the controller will place the items at the player's pawn. See the note below to customize this:
When using the basic inventory controller (BLInventoryControllerComponent
), override the GetDropTransform
and GetDropInstigator
functions.
When using abilities for inventory manipulation, use the Drop World Item
ability task. You may specify the items' drop transform and instigator in the task parameters.
Picking Up
To pick up items, simply transfer the items from the world item's slot to another inventory. If a player wants to pick up items, make sure you always use the Request
functions on their InventoryController
.
Some games want items to automatically pick up when the player walks within range. To do this, add an OnActorBeginOverlap
override on the world item (or the player pawn). Check if the overlapping actor is a player pawn, then get their inventory controller and request pick up.