How can I use an Array + Enum for Identification purposes?

Hey! I am trying to use an Array and an Enum to create a collectables system, that looks a bit less “programmy”. So this is the array I am trying to use:

USTRUCT()
struct FCollectableID
{
	GENERATED_USTRUCT_BODY()

	FString Name;
	int ID;
	bool isThisType;
};

UCLASS()
class ACollectable : public AActor
{
	GENERATED_UCLASS_BODY()

	//Collectable Identification
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Stats)
		TArray<FCollectableID> PUidentification;
}

So what I am trying to do is create an array with which I can easily select the type of powerup that the Actor holds. I am sending the power up via this function:

void ACollectable::GiveCollectable(class AFPSCharacter* pl)
{
if (pl)
	{
	pl->ApplyPowerUp(PUamnt, PUidenfication->ID?);
	}
}

The problem is, I dont have any experience with Arrays and don’t know how to code it so that the game finds the unit in the array that has “isThisType” as true. I also wanted to ask a question about enums that I thought closly linked to this question. I have created one in my character class, for the powerups:

UENUM(BlueprintType)       //"BlueprintType" is essential specifier
namespace EPowerups
{
	//256 entries max
	enum Type
	{
		Armor,
		Health,
		Stamina
	};
}

How could I get access to these, so that I could do the following:

void AFPSCharacter::ApplyPowerUp(int32 amnt, int32 PUid)
{
	if (PUid == Health)
	{
		plHealth = FMath::Clamp(plHealth += amnt, 0, plMaxHealth);
		FString curHealth = FString::FromInt(plHealth);
		GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Green, curHealth);
	}
}

Sorry if this is a pretty long question, but I thought it was pretty important for me to fully understand Unreal Engine 4 C++.

#Enum Question

“How could I get access to these, so that I could do the following:”

instead of

void AFPSCharacter::ApplyPowerUp(int32 amnt, int32 PUid)
{
    if (PUid == Health)
    {

do this!

  void AFPSCharacter::ApplyPowerUp(int32 amnt, const EPowerups::Type PowerUpType)
    {
        if (PowerUpType == EPowerups::Health)
        {

#Array Question

If you want to search through an array and find ID matches, you can do this:

//the ID to check for
int32 TheIDToCheckFor = 9000; //something;

for(const FCollectableID& EachCollectable : PUidentification)
{
  if(EachCollectable.ID == TheIDToCheckFor )
  {
     //found a match!
     //do stuff
     break; //if only wanting 1 match, ends loop early 
   }
}

#NEVER USE TYPE INT

in your struct:

int ID;

should become

int32 ID;

If you have more array questions please post a separate thread about it

also

check out my wiki tutorial

#Dynamic Array Wiki Tutorial

Rama

Best guy :smiley: 10/10 for all your answers, you are a blessing to the community.