Daily Unreal Column #36 - Printing function name
If I were to cut a finger every time I see people writing literal function name when they are adding debug logs I would be fingerless long time ago. Here is how to do it right.
The proper way of accessing current function name is using __FUNCTION__
identifier. To use it as an FString
and avoid compilation errors on different platforms (looking at you PS5) you need to wrap it with either:
ANSI_TO_TCHAR(__FUNCTION__)
or with
StringCast<TCHAR>(__FUNCTION__).Get()
(not an option in UE4 AFAIK)
Your logs should look like this then:
UE_LOG(
LogTemp,
Error,
TEXT("[%s] Error details"),
*StringCast<TCHAR>(__FUNCTION__).Get());