Creating an InventoryComponent for an RPG

An InventoryComponent enables its containing Actor to store InventoryActors in its inventory, and place them back into the game world.

Getting ready

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 GameMode.

How to do it...

  1. Create an ActorComponent subclass using the engine called InventoryComponent, then add the following code to it:
    UPROPERTY() TArray<AInventoryActor*> CurrentInventory; UFUNCTION() int32 AddToInventory(AInventoryActor* ...

Get Unreal Engine 4 Scripting with C++ Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.