void FBehaviorTreeDebugger::FindLockedDebugActor(UWorld* World)
{
	APlayerController* LocalPC = GEngine->GetFirstLocalPlayerController(World);
	if (LocalPC && LocalPC->GetHUD() && LocalPC->GetPawnOrSpectator())
	{
		AGameplayDebuggingReplicator* DebuggingReplicator = NULL;
		for (TActorIterator<AGameplayDebuggingReplicator> It(World); It; ++It)
		{
			AGameplayDebuggingReplicator* A = *It;
			if (!A->IsPendingKill())
			{
				DebuggingReplicator = A;
				break;
			}
		}

		const APawn* LockedPawn = DebuggingReplicator != NULL ? Cast<APawn>(DebuggingReplicator->GetSelectedActorToDebug()) : NULL;
		UBehaviorTreeComponent* TestInstance = FindInstanceInActor((APawn*)LockedPawn);
		if (TestInstance)
		{
			TreeInstance = TestInstance;

#if USE_BEHAVIORTREE_DEBUGGER
			ActiveStepIndex = TestInstance->DebuggerSteps.Num() - 1;
#endif
		}
	}
}
void AGameplayDebuggerReplicator::OnSelectPlayer()
{
#if ENABLED_GAMEPLAY_DEBUGGER
	APlayerController* MyPC = DebugCameraController.IsValid() ? DebugCameraController.Get() : GetLocalPlayerOwner();
	APawn* MyPawn = MyPC ? MyPC->GetPawnOrSpectator() : nullptr;
	if (MyPawn)
	{
		ServerSetActorToDebug(MyPawn);
	}
#endif
}