Creating an InventoryComponent for an RPG
InventoryComponent enables its containing
Actor to store
InventoryActors in its inventory, and place them back into the game world.
Make sure you've followed the Axis Mappings – keyboard, mouse and gamepad directional input for an FPS character recipe in Chapter 6, Input and Collision, before continuing with this recipe, as it shows you how to create a simple character.
Also, the recipe Instantiating an Actor using SpawnActor in this chapter shows you how to create a custom
How to do it...
- Create an
ActorComponentsubclass using the engine called
InventoryComponent, then add the following code to it:
UPROPERTY() TArray<AInventoryActor*> CurrentInventory; UFUNCTION() int32 AddToInventory(AInventoryActor* ...