Hey!đź‘‹ ubyte.dev just recently launched. It's dedicated towards Unreal Engine 5.

Log function names automatically with __FUNCTIONW__

November 27, 2022
Lucas Tchikhinachvili
Using certain macros (or compiler-generated fields) such as __FUNCTION__ and __FUNCTIONW__

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

__func__

TestFunction

__FUNCTION__

AMyActor::TestFunction

__FUNCTIONW__

AMyActor::TestFunction

__FUNCSIG__

void AMyActor::TestFunction(AActor* UselessArgument)

__PRETTY_FUNCTION__

void AMyActor::TestFunction(AActor* UselessArgument)

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:

  1. __PRETTY_FUNCTION__ may not compile. Use __FUNCSIG__ instead.

  2. 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);
    }
cross linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram