官术网_书友最值得收藏!

UE4 – logging with UE_LOG

Logging is extremely important for outputting internal game data. Using log tools lets you print information into a handy little Output Log window in the UE4 editor.

Getting ready

When coding, we may sometimes want to send some debug information out to the UE log window. This is possible using the UE_LOG macro. Log messages are an extremely important and convenient way to keep track of information in your program as you are developing it.

How to do it...

  1. In your code, enter a line of code using the form:
    UE_LOG(LogTemp, Warning, TEXT("Some warning message") );
    
  2. Turn on the Output Log inside the UE4 editor to see your log messages printed in that window as your program is running.

How it works...

The UE_LOG macro accepts a minimum of three parameters:

  • The Log category (we used LogTemp here to denote a log message in a temporary log)
  • The Log level (we used a warning here to denote a log message printed in yellow warning text)
  • A string for the actual text of the log message itself

Do not forget the TEXT() macro around your log message text! It promotes the enclosed text to Unicode (it prepends an L) when the compiler is set to run with Unicode on.

UE_LOG also accepts a variable number of arguments, just like printf() from the C programming language.

int intVar = 5;
float floatVar = 3.7f;
FString fstringVar = "an fstring variable";
UE_LOG(LogTemp, Warning, TEXT("Text, %d %f %s"), intVar, floatVar, *fstringVar );

There will be an asterisk * just before FString variables when using UE_LOG to dereference the FString to a regular C-style TCHAR pointer.

Tip

TCHAR is usually defined as a variable type where, if Unicode is being used in the compile, the TCHAR resolves to wchar_t. If Unicode is off (compiler switch _UNICODE not defined), then TCHAR resolves to simply char.

Don't forget to clear your log messages after you no longer need them from the source!

主站蜘蛛池模板: 克山县| 南汇区| 胶州市| 绥中县| 东乡县| 岳阳市| 宜良县| 米泉市| 富顺县| 理塘县| 板桥市| 武山县| 贺兰县| 雅安市| 嘉禾县| 东海县| 宁陕县| 连云港市| 吕梁市| 谢通门县| 柳林县| 泰安市| 海原县| 军事| 二连浩特市| 甘洛县| 邯郸市| 崇文区| 湖口县| 金堂县| 湾仔区| 松原市| 凤凰县| 连山| 淮滨县| 两当县| 荃湾区| 华亭县| 赤水市| 如东县| 齐齐哈尔市|