How to convert UEnum type to String? C++

Hello, is this even possible using C++ in ue4 to print all the array elements?
what is the alternative for GetEnumeratorUserFriendlyName?
I want to print all the elements located in Array, how to do this? unable to figure out how to convert UEnum type to String?

TArray<EItemType> Arr{};
for (auto& Array : Arr) //Arr is of type UEnum EItemType
		{
			FString Elements = TEXT("Enum Elements: ") + EnumToString(TEXT("EItemType"), static_cast<uint8>(Array));

printf("%s", *Elements); //macro
		}

Error

blueprint

any help appreciated in my learning progress

you can convert it using the inbuilt function GetValueAsString()

/**
	 * @param EnumeratorValue  Enumerator Value.
	 *
	 * @return the string associated with the enumerator for the specified enum value for the enum specified by the template type.
	 */
template<typename EnumType>
	FORCEINLINE static FString GetValueAsString(const EnumType EnumeratorValue)
	{
		// For the C++ enum.
		static_assert(TIsEnum<EnumType>::Value, "Should only call this with enum types");
		return GetValueAsName(EnumeratorValue).ToString();
	}

simply call this function under UE_LOG macro to print all the stored data to console.
so in your for loop.

for (auto& Array : Arr)
	{
      UE_LOG(LogTemp, Log, TEXT("The Elements in Array: %s"), *UEnum::GetValueAsString(Array));
	}

hope it helps , test it and show me what results now you will have.
cheers!

3 Likes

Just as complement:

2 Likes

thank you very much sir, this just solved the big issue , Really appreciated :slight_smile:
the results i have now in the image, perfect as wanted, all the items are generated randomly


now i can spawn them any where in the level using this method Spawn Actor From Class

thank you very much for big contribution helping me :slight_smile:

1 Like

welcome, glad I helped )

1 Like

these wikis are super useful

2 Likes

Just
UEnum::GetValueAsString(YourEnum::Value)