Keywords: UE4, Programming Debug Tricks Notes

Shipping 版本开启log

添加以下到 Target.cs 的构造函数中(Editor.Target.cs不需要添加):

bUseLoggingInShipping = true;

最终log文件生成位置在:

C:\Users\<WindowsUsername>\AppData\Local\<ProjectName>\Saved\Logs

bUseLoggingInShipping = true; 只对源码编译的引擎版本有效,Launcher版本无效。Launcher版本无法在Shipping模式下开启log。

VisualStudio中查看UE4 log
如果要查看VS命令行的UE4相关log,需要Debug模式(VS的Debug,即F5,不是UE4的DebugGame)
Android Device Monitor 打印log

比如UE4工程的C++代码中有如下log打印语句:

UE_LOG(LogTemp, Display, TEXT("aaaaaaa"));

我们希望这句话在Android Device Monitor中能也能够打印出来,默认情况下,需要在将设备的Config设置为DebugGame或者Development,Shipping下则不会打印。

Android Device Monitor中显示的游戏UE_LOG,统一都是Debug级别的蓝色,即使是UE_LOG的级别为Error,显示的也是蓝色。

Useful API

How to debug inline function?

Use FORCEINLINE_DEBUGGABLE.

Example:
from Engine\Source\Runtime\RHI\Public\RHICommandList.h:

FORCEINLINE_DEBUGGABLE void CopyTexture(FRHITexture* SourceTextureRHI, FRHITexture* DestTextureRHI, const FRHICopyTextureInfo& CopyInfo)
{
}

Setup:
Modify “Engine\Source\Runtime\Core\Public\Misc\CoreMiscDefines.h”:
Origin:

#if UE_BUILD_DEBUG
    #define FORCEINLINE_DEBUGGABLE FORCEINLINE_DEBUGGABLE_ACTUAL
#else
    #define FORCEINLINE_DEBUGGABLE FORCEINLINE
#endif

New:

#if UE_BUILD_DEBUG
    #define FORCEINLINE_DEBUGGABLE FORCEINLINE_DEBUGGABLE_ACTUAL
#else
    #if UE_BUILD_DEVELOPMENT
        #define FORCEINLINE_DEBUGGABLE FORCEINLINE_DEBUGGABLE_ACTUAL
    #else
        #define FORCEINLINE_DEBUGGABLE FORCEINLINE
    #endif
#endif
How print log in low level
FPlatformMisc::LowLevelOutputDebugStringf(TEXT("FWebBrowserTextureResource:CopySample 11"));
How to record tracing data for Insights

Example:

void UCharacterMovementComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
    SCOPED_NAMED_EVENT(UCharacterMovementComponent_TickComponent, FColor::Yellow);
    SCOPE_CYCLE_COUNTER(STAT_CharacterMovement);
    SCOPE_CYCLE_COUNTER(STAT_CharacterMovementTick);
    CSV_SCOPED_TIMING_STAT_EXCLUSIVE(CharacterMovement);
    ...
}

Efficiency is doing the thing right. Effectiveness is doing the right thing. ― Peter F. Drucker