Download

How add items to my inventory array?

Hi Guys;
In my pickup actor, I have an Enum variable called “PickupInventoryTypes”:



    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = PickupSettings)
    TEnumAsByte<PickupInvTypes>PickupInventoryTypes;


And I have a FString Array in my pawn class:


    UPROPERTY(EditAnywhere, BlueprintReadWrite )
    TArray<FString> MyInventories;

When pawn collides with my Pickup-Actor, I would like to get Enum value (PickupInventoryTypes) , and add it to my FString Array.
Problem is , my codes here does not work :


void APawnCharacter::BeginOverlap(UPrimitiveComponent* OverlappedComponent,    AActor* OtherActor)
{
    MyInventories.AddUnique(Cast<APickup>(*OtherActor->GetClass()) ->PickupInventoryTypes.GetValue());
}


Visual Studio complaints:



 ... error C2664: 'int32 TArray<FString,FDefaultAllocator>::AddUnique(const FString &)': cannot convert argument 1 from 'PickupInvTypes' to 'FString &&'


Thanks for helping.
MSD.

Rama knows it :slight_smile:

This is how to get an enum as a string:


FString GetVictoryEnumAsString(EVictoryEnum::Type EnumValue)
{
  const UEnum* EnumPtr = FindObject<UEnum>(ANY_PACKAGE, TEXT("EVictoryEnum"), true);
  if(!EnumPtr) return FString("Invalid");
 
  return EnumPtr->GetEnumName((int32)EnumValue); // for EnumValue == VE_Dance returns "VE_Dance"
}

Here is the full article:

https://wiki.unrealengine.com/Enums_For_Both_C%2B%2B_and_BP

PS: Although in my project I made a conversion function using a switch