How to log FName from array?

Hi, how to log a member from array of type FName.

TArray<FIDStruct> IDStruct_Arr{}
FName ID; //member of the IDStruct
for (auto& Array : IDStruct_Arr)
	{
     //How to Log the Array.ID here?
	}

an example of logging actor’s name.

`UE_LOG(LogTemp, Warning, TEXT("The Actor's name is %s"), *YourActor->GetName());`

Snippet from code logging input to OpenLevel() which requires an FName:

FName mapName;

LOG("ProcessLoadMapRequest() - load map: %s ...", *mapName.ToString());

UGameplayStatics::OpenLevel(GetWorld(), mapName);

LOG("ProcessLoadMapRequest() - load map: %s complete.", *mapName.ToString());
1 Like

if your variable ID is declared in the IDStruct you can access it and convert directly

UE_LOG(LogTemp, Warning, TEXT("Val is: %s"),  *Array.ID.ToString());

hope it helps
cheers!

2 Likes

both solutions working perfectly, but I don’t want to convert to string, I want to log the FName directly if possible.

Thank you

Not aware of any other way to log fnames. Here’s the string handling doc:

String Handling | Unreal Engine Documentation

Also, not sure about anyone else, but we purged all FNames from code due to encountering weird issues with them in release / cooked builds. Also they are harder to log. If a base Unreal call requires it then we convert where needed.

1 Like

FName is actually a string in some cases.
ex: if you wan to convert FText to FName

FText myText;
FName name = FName(*myText.ToString());
other types of quick conversion:
// FText: FString to FText
    FString Str;
    FText text = FText::FromString(Str);
 
    // FText: FName to FText
    FName name;
    FText text = FText::FromName(name);
   
 
    // FString: FText to FString
    FText text;
    FString str = text.ToString();
 
    // FString: FName to FString
    FName name;
    FString str = name.ToString();
 
 
    // FName: FString to FName
    FString Str;
    FName name = FName(*Str);

and follow the documentation @Shmoopy1701 shared.

hope it helps
cheers

1 Like

thanks very much for @Shmoopy1701 @c0r37py

1 Like

NP. One last thing. This thread has some macro to simplify your log statements:

UE_LOG with format as variable - Programming & Scripting / C++ - Unreal Engine Forums

1 Like

very hot post :fire: :fire: :fire: :fire: thank you for sharing this information, it really helps to make life easy

1 Like