Capture left/right mouse click globally

Hi,

I have a problem with mouse click (left or right).
I take an example from the sample “Puzzle”.
One different is that I need capture mouse click from Pawn (witch is connected to PlayerController) no matter what was clicked.
(In sample puzzle blocks are “clickable” by its geometry, but in my idea there is no “geometry”).

I want capture click on screen and create object in this position, but I stuck at capture left click, I can get mouse coordinates from Pawn but not the click event. Position I’m getting form Pawn::Tick function.

[UPDATE]
Im using this->OnClicked.AddDynamic(this, &ATouchTestPawn::MouseClick) from Pawn constructor.
Im binding InputComponent->BindAction("TriggerClick", EInputEvent::IE_Pressed, this, &ATouchTestPawn::TriggerClick) from Pawn::SetupPlayerInputComponent but delegate is not called.

Have you tied your “TriggerClick” action to the left mouse button?

You can do this in the editor in the Project Settings window. Under Engine->Input, there’s a Bindings panel.

You can also do this in code by collecting the UInputSettings object and adding an AxisMapping or ActionMapping (for a click event you would use ActionMapping).

UInputSettings* InputSettings = const_cast<UInputSettings>(GetDefault<UInputSettings>());
if (InputSettings) {
    
    //create action mapping
    FInputActionKeyMapping NewMapping = FInputActionkeyMapping();
    NewMapping.ActionName = "TriggerClick";
    NewMapping.Key = FKey("LeftMouseButton");
    NewMapping.bShift = false;
    NewMapping.bCtrl = false;
    NewMapping.bAlt = false;
    NewMapping.bCmd = false;

    //add to input settings
    InputSettings->AddActionMapping(NewMapping);

}

You can also manually add the action mapping in your Input.ini file.

See:

Input Action And Axis Mappings In UE4 - Unreal Engine

FInputActionKeyMapping | Unreal Engine Documentation

FKey | Unreal Engine Documentation

A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums

UPlayerInput | Unreal Engine Documentation

UPlayerInput::AddActionMapping | Unreal Engine Documentation

Thanks for help, now it’s working.

Solved.

[Update]
Maybe someone see this as useful.
In “mobile” project you need using InputComponent->BindTouch instead InputComponent->BindAction