Logging automatically generated function string literals
Underneath are what certain macros (or compiler-generated fields) automatically expand to inside the scope of void AMyActor::TestFunction(AActor* UselessArgument)
:
Macro / field | Expands to |
|
|
|
|
|
|
|
|
|
|
Usage example (with output commented)
void AMyActor::TestFunction(AActor* UselessArgument)
{
// TestFunction
UE_LOG(LogTemp, Warning, TEXT("%s"), ANSI_TO_TCHAR(__func__));
// AMyActor::TestFunction
UE_LOG(LogTemp, Warning, TEXT("%s"), TEXT(__FUNCTION__));
// AMyActor::TestFunction
UE_LOG(LogTemp, Warning, TEXT("%s"), __FUNCTIONW__);
// void AMyActor::TestFunction(AActor* UselessArgument)
UE_LOG(LogTemp, Warning, TEXT("%s"), TEXT(__FUNCSIG__));
// May not compile. Use __FUNCSIG__
// void AMyActor::TestFunction(AActor* UselessArgument)
UE_LOG(LogTemp, Warning, TEXT("%s"), TEXT(__PRETTY_FUNCTION__));
}
Notes:
__PRETTY_FUNCTION__
may not compile. Use__FUNCSIG__
instead.If you’re usingÂ
__FUNCSIG__
 and get this:void __cdecl AInteractableActor::BeginPlay(void)
There's a hack to remove the "__cdecl" part:
{ FString Funcsig = __FUNCSIG__; int32 Index = Funcsig.Find("__cdecl"); if (Index != -1) { Funcsig.RemoveAt(Index, 8); } UE_LOG(LogTemp, Warning, TEXT("%s"), *Funcsig); }