void UGameplayDebuggingControllerComponent::OnActivationKeyPressed()
{
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
	if (GetDebuggingReplicator() && PlayerOwner.IsValid())
	{
		if (!bToolActivated)
		{
			Activate();
			SetComponentTickEnabled(true);

			BindAIDebugViewKeys(AIDebugViewInputComponent);
			if (PlayerOwner.IsValid())
			{
				PlayerOwner->PushInputComponent(AIDebugViewInputComponent);
			}

			GetDebuggingReplicator()->EnableDraw(true);
			GetDebuggingReplicator()->ServerReplicateMessage(nullptr, EDebugComponentMessage::ActivateReplication, EAIDebugDrawDataView::Empty);
		}

		ControlKeyPressedTime = GetWorld()->GetTimeSeconds();
		EnableTargetSelection(true);
	}
#endif //!(UE_BUILD_SHIPPING || UE_BUILD_TEST)
}
void UGameplayDebuggingControllerComponent::OnActivationKeyPressed()
{
	if (GetDebuggingReplicator() && PlayerOwner.IsValid())
	{
		if (!bToolActivated)
		{
			Activate();
			SetComponentTickEnabled(true);

			BindAIDebugViewKeys();
			GetDebuggingReplicator()->EnableDraw(true);
			GetDebuggingReplicator()->ServerReplicateMessage(NULL, EDebugComponentMessage::ActivateReplication, EAIDebugDrawDataView::Empty);
		}

		ControlKeyPressedTime = GetWorld()->GetTimeSeconds();
		EnableTargetSelection(true);
	}
}
void UGameplayDebuggingControllerComponent::ToggleDebugCamera()
{
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
	if(!bToolActivated || PlayerOwner == nullptr)
	{
		return;
	}

	if (DebugCameraController.IsValid() == false)
	{
		// spawn if necessary
		// and ungly @HACK to be able to spawn camera in game world rather then
		// in editor world (if running PIE). Hate it, but it works, and 
		// this is a debugging tool		
		{
			FActorSpawnParameters SpawnInfo;
			SpawnInfo.bNoCollisionFail = true;
			SpawnInfo.Owner = PlayerOwner->GetWorldSettings();
			SpawnInfo.Instigator = PlayerOwner->Instigator;
			DebugCameraController = GetWorld()->SpawnActor<ADebugCameraController>(SpawnInfo);
		}

		if (DebugCameraController.IsValid())
		{
			// set up new controller
			DebugCameraController->OnActivate(PlayerOwner.Get());

			// then switch to it
			PlayerOwner->Player->SwitchController(DebugCameraController.Get());

			FActorSpawnParameters SpawnInfo;
			SpawnInfo.Owner = PlayerOwner.Get();
			SpawnInfo.Instigator = PlayerOwner->Instigator;
			SpawnInfo.bNoCollisionFail = true;
			SpawnInfo.ObjectFlags |= RF_Transient;	// We never want these to save into a map
			AGaneplayDebuggerProxyHUD* ProxyHUD = GetWorld()->SpawnActor<AGaneplayDebuggerProxyHUD>(SpawnInfo);
			ProxyHUD->RedirectedHUD = PlayerOwner->MyHUD;
			DebugCameraController->MyHUD = ProxyHUD;
			BindAIDebugViewKeys(DebugCameraInputComponent);
			DebugCameraInputComponent->BindKey(ActivationKey, IE_Pressed, this, &UGameplayDebuggingControllerComponent::OnActivationKeyPressed);
			DebugCameraInputComponent->BindKey(ActivationKey, IE_Released, this, &UGameplayDebuggingControllerComponent::OnActivationKeyReleased);
			DebugCameraController->PushInputComponent(DebugCameraInputComponent);

			DebugCameraController->ChangeState(NAME_Default);
			DebugCameraController->ChangeState(NAME_Spectating);
		}
	}
	else
	{
		DebugCameraController->PopInputComponent(DebugCameraInputComponent);
		DebugCameraInputComponent = nullptr;
		DebugCameraController->OriginalPlayer->SwitchController(DebugCameraController->OriginalControllerRef);
		DebugCameraController->OnDeactivate(DebugCameraController->OriginalControllerRef);
		GetWorld()->DestroyActor(DebugCameraController.Get(), false, false);
		DebugCameraController = nullptr;

		if(AIDebugViewInputComponent == nullptr)
		{
			BindAIDebugViewKeys(AIDebugViewInputComponent);
		}
		if (PlayerOwner.IsValid())
		{
			PlayerOwner->PushInputComponent(AIDebugViewInputComponent);
		}

	}

#endif //!(UE_BUILD_SHIPPING || UE_BUILD_TEST)
	}