UE网络-断点指定Actor

仿照CVarRepGraphConditionalBreakpointActorName, 添加自己需要条件段断点的地方.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
static TAutoConsoleVariable<FString> CVarRepGraphConditionalBreakpointActorName(TEXT("Net.RepGraph.ConditionalBreakpointActorName"), TEXT(""), 
TEXT("Helper CVar for debugging. Set this string to conditionally log/breakpoint various points in the repgraph pipeline. Useful for bugs like 'why is this actor channel closing'"), ECVF_Default );

// 使用:
FORCEINLINE bool RepGraphConditionalActorBreakpoint(AActor* Actor, UNetConnection* NetConnection)
{
#if !(UE_BUILD_SHIPPING)
if (CVarRepGraphConditionalBreakpointActorName.GetValueOnGameThread().Len() > 0 && GetNameSafe(Actor).Contains(CVarRepGraphConditionalBreakpointActorName.GetValueOnGameThread()))
{
return true;
}

// Alternatively, DebugActorConnectionPair can be set by code to catch a specific actor/connection pair
if (DebugActorConnectionPair.Actor.Get() == Actor && (DebugActorConnectionPair.Connection == nullptr || DebugActorConnectionPair.Connection == NetConnection ))
{
return true;
}
#endif
return false;
}

实践:

1
2
3
4
5
6
7
8
9
10
11
static FString BreakpointActorName;
static FAutoConsoleVariableRef CVarBreakpointActorName(
TEXT("net.BreakpointActorName"),
BreakpointActorName,
TEXT("BreakpointActorName.")
);

if (BreakpointActorName.Len() > 0 && GetNameSafe(Actor).Contains(BreakpointActorName))
{
UE_LOG(LogNet, Warning, TEXT("UActorChannel::ReplicateActor Debug Actor[%s]"), *BreakpointActorName);
}