How to do it...

  1. Create an ActorComponent subclass using the engine called InventoryComponent:
  1. Inside of the InventoryComponent.h file, add the following code:
#pragma once#include "CoreMinimal.h"#include "Components/ActorComponent.h"#include "InventoryComponent.generated.h"UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )class CHAPTER_04_API UInventoryComponent : public UActorComponent{    GENERATED_BODY()public:     // Sets default values for this component's properties    UInventoryComponent();    UPROPERTY()    TArray<AInventoryActor*> CurrentInventory;    UFUNCTION()    int32 AddToInventory(AInventoryActor* ActorToAdd);    UFUNCTION() void ...

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

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