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

**URL:** <https://forums.unrealengine.com/t/how-can-i-use-an-array-enum-for-identification-purposes/284651>\
**Category:** Editor Scripting\
**Tags:** arrays, tarray, unreal-engine, CPP, question\
**Created:** [May 31, 2014, 12:05pm UTC](https://forums.unrealengine.com/t/how-can-i-use-an-array-enum-for-identification-purposes/284651 "2014-05-31T12:05:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_44db827a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_44db827a](https://forums.unrealengine.com/u/anonymous_user_44db827a)\
**Post date:** [May 31, 2014, 12:05pm UTC](https://forums.unrealengine.com/t/how-can-i-use-an-array-enum-for-identification-purposes/284651/1 "2014-05-31T12:05:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [May 31, 2014, 7:39pm UTC](https://forums.unrealengine.com/t/how-can-i-use-an-array-enum-for-identification-purposes/284651/2 "2014-05-31T19:39:05Z")

</div>

#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

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

Rama

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_44db827a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_44db827a](https://forums.unrealengine.com/u/anonymous_user_44db827a)\
**Post date:** [June 1, 2014, 3:04pm UTC](https://forums.unrealengine.com/t/how-can-i-use-an-array-enum-for-identification-purposes/284651/3 "2014-06-01T15:04:13Z")

</div>

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