Having issues with enabling/disabling mouse input

This is much easier to show than explain so I made a short video demonstrating my two issues.

ISSUE 1: Disabling / unsetting bShowMouseCursor doesn’t seem to undo everything that setting bShowMouseCursor does (IE setting bShowMouseCursor enables the mouse and starts tracking it, unsetting bShowMouseCursor just hides it).

ISSUE 2: Mouse doesn’t even show up in the play in editor views. Only in standalone.

I know this has come up but the solutions seemed very hacky. Any help would be greatly appreciated.


// Called to bind functionality to input
void AVehicleEditorPawn::SetupPlayerInputComponent(class UInputComponent * InputComponent)
{
	Super::SetupPlayerInputComponent(InputComponent);

	InputComponent->BindAction("Secondary",
		IE_Pressed, this, &AVehicleEditorPawn::SecondaryPressed);
	InputComponent->BindAction("Secondary",
		IE_Released, this, &AVehicleEditorPawn::SecondaryReleased);

	// ...
}

void AVehicleEditorPawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	static auto * const PlayerController = GetWorld()->GetFirstPlayerController();

	// Enable / disable cursor based on Secondary
	PlayerController->bShowMouseCursor = !SecondaryCurrentlyPressed;
	PlayerController->bEnableClickEvents = !SecondaryCurrentlyPressed;
	PlayerController->bEnableMouseOverEvents = !SecondaryCurrentlyPressed;

	// ..
}

// Secondary Pressed
void AVehicleEditorPawn::SecondaryPressed()
{
	SecondaryCurrentlyPressed = true;
}

// Secondary Released
void AVehicleEditorPawn::SecondaryReleased()
{
	SecondaryCurrentlyPressed = false;
}


I’m not a billion percent happy with the solution but I did manage to capture and hold the mouse state…


void AVehicleEditorPawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	// ...

	// Enable / disable cursor based on Secondary
	PlayerController->bShowMouseCursor = !SecondaryCurrentlyPressed;
	PlayerController->bEnableClickEvents = !SecondaryCurrentlyPressed;
	PlayerController->bEnableMouseOverEvents = !SecondaryCurrentlyPressed;

	if (SecondaryCurrentlyPressed)
	{
		// Force hold mouse position
		Viewport->SetMouse(MousePosition.X, MousePosition.Y);
	}

	// ...
}

void AVehicleEditorPawn::SecondaryPressed()
{
	SecondaryCurrentlyPressed = true;

	if (PlayerController)
	{
		// Capture mouse position
		PlayerController->GetMousePosition(MousePosition.X, MousePosition.Y);
	}
}