Declaring the backpack
We can represent the player's backpack as a simple TMap<FString, int>
item. To allow your player to gather items from the world, open the Avatar.h
file and add the following TMap
declaration:
class APickupItem; // forward declare the APickupItem class, // since it will be "mentioned" in a member function decl below UCLASS() class GOLDENEGG_API AAvatar : public ACharacter { GENERATED_UCLASS_BODY() // A map for the player's backpack TMap<FString, int> Backpack; // The icons for the items in the backpack, lookup by string TMap<FString, UTexture2D*> Icons; // A flag alerting us the UI is showing bool inventoryShowing; // member function for letting the avatar have an item void Pickup( APickupItem *item ); // ... rest of Avatar.h same as before };
Forward declaration
Before
AAvatar
class, notice that we have a class APickupItem
forward declaration. Forward declarations are needed in a code...