- Unreal Engine 4 Scripting with C++ Cookbook
- William Sherif Stephen Whittle
- 330字
- 2021-07-08 10:50:45
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...
- In your code, enter a line of code using the form:
UE_LOG(LogTemp, Warning, TEXT("Some warning message") );
- 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!
- Arduino by Example
- 華為HMS生態(tài)與應(yīng)用開發(fā)實(shí)戰(zhàn)
- Visual Basic程序設(shè)計(jì)(第3版):學(xué)習(xí)指導(dǎo)與練習(xí)
- 從0到1:HTML+CSS快速上手
- Mastering Python High Performance
- Teaching with Google Classroom
- UVM實(shí)戰(zhàn)
- Webpack實(shí)戰(zhàn):入門、進(jìn)階與調(diào)優(yōu)
- Android傳感器開發(fā)與智能設(shè)備案例實(shí)戰(zhàn)
- 新印象:解構(gòu)UI界面設(shè)計(jì)
- Arduino可穿戴設(shè)備開發(fā)
- Android Development Tools for Eclipse
- STM8實(shí)戰(zhàn)
- ABAQUS6.14中文版有限元分析與實(shí)例詳解
- 透視C#核心技術(shù):系統(tǒng)架構(gòu)及移動端開發(fā)