Mouse click not captured in player controller

Hey guys,

i am running out of ideas. I just can’t manage to capture a mouse click. So here is the scenario:

  • I have a UProceduralMeshComponent as the RootComponent of an AActor class added in my level
  • Also i have a UMG widget as the HUD with a simple button
  • I was adding a mouse click action entry in my Project settings Input section
  • I am binding the action to a function which is never called
  • I am starting the game in PIE

Here is some code in my ALevelPlayerController:

void ALevelPlayerController::BeginPlay()
{
	Super::BeginPlay();

	EnableInput(this);
}

void ALevelPlayerController::SetupInputComponent()
{
	Super::SetupInputComponent();

	bEnableClickEvents = true;
	bShowMouseCursor = true;
	
	FInputModeGameAndUI inputMode;
	inputMode.SetHideCursorDuringCapture(true);
	inputMode.SetLockMouseToViewport(true);
	SetInputMode(inputMode);
	
	InputComponent->BindAction("TerrainLeftClicked", IE_Pressed, this, &ALevelPlayerController::OnLeftMouseButtonClicked);
}

void ALevelPlayerController::OnLeftMouseButtonClicked()
{
    // There is a lot of code here. Unfortunately it never gets executed :(
}

For some reason the OnLeftMouseButtonClicked fucntion is never called. I was reading a lot of solution suggestions in this forums and the rest of internet. All the suggestions i found i was adding in my code without any success. Any help is highly appreciated.

Cheers
DeKande

There is a Member called ClickEventKeys on a PlayerController. You will have to register the left mouse button there if you want to generate click events for it. I have a Blueprint where I can select from the keys, if you want to keep it C++ only, then you will have to create an FKey from the proper key name. For the left mouse button this would just be FKey("LeftMouseButton"); (I think).

Hey,

thanks for your answer! Unfortunately the left mouse button was already added in the ClickEventKeys. So no success. I am using a workaround now. I use the OnClicked event in the actor class to know if the actor was clicked.

Still i think it should be possible just to capture if the left mouse key was pressed/released.

Cheers DeKande

  1. project setting → filtering with “mouse” → uncheck USE MOUSE FOR TOUCH

  2. check variables about mouse in your playercontroller class

Thank you so very much, this solved my problem in the AR project :slight_smile: