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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.