AActor OnClicked, not reacting to right click

I have the following code:

this->capsuleComponent->OnClicked.AddUniqueDynamic(this, &AInventoryItem::ItemOnClicked);

This method gets fired when left click occurs over the top of an actor but not when right click.

void AInventoryItem::ItemOnClicked(UPrimitiveComponent* touchedComponent, FKey buttonPressed)
{
    // This does not fire when right click is pressed.
}

What am i missing?

This is what i was aiming for:

void AInventoryItem::ItemOnClicked(UPrimitiveComponent* touchedComponent, FKey buttonPressed)
{
	AMainPlayerController* mainPlayerController = (AMainPlayerController*)this->GetWorld()->GetFirstPlayerController();

	if (buttonPressed == EKeys::LeftMouseButton)
	{
		// Run default actions
		UE_LOG(LogTemp, Warning, TEXT("AInventoryItem::ItemOnClicked was called. left mouse button was pressed"));
	}
	else if (buttonPressed == EKeys::RightMouseButton)
	{
		// Bring up action menu
		mainPlayerController->ToggleActionMenu();
		UE_LOG(LogTemp, Warning, TEXT("AInventoryItem::ItemOnClicked was called. right mouse button was pressed"));
	}
}

EDIT:

I’ve just seen the comment:

/** Event called when the left mouse button is released while the mouse is over this component click events are enabled in the player controller */
	UPROPERTY(BlueprintAssignable, Category="Input|Mouse Input")
	FComponentOnReleasedSignature OnReleased;

so what is the method that accepts right click?..

Why was this marked as the answer??? When i haven’t even tried it yet?

Thanks, the registration of the right mouse button was the answer. Thanks!

In your PlayerController class, you can add:

ClickEventKeys.Add(EKeys::RightMouseButton);

In the base PlayerController.cpp constructor, there is:

ClickEventKeys.Add(EKeys::LeftMouseButton);

Later on, in InputKey( ), there is a condition looking that ClickEventKeys has whatever key is being passed in. Later on in that function there is:

if (ClickedPrimitive)
{
	switch(EventType)
	{
		case IE_Pressed:
		case IE_DoubleClick:
			ClickedPrimitive->DispatchOnClicked(Key);
		break;

		case IE_Released:
			ClickedPrimitive->DispatchOnReleased(Key);
		break;
    }
}

ClickedPrimitive->DisplatchOnReleased is the function that ends up broadcasting the OnReleased Delegate.

Dayum, now I can’t wait to get out of work and give this a try. Curse the next 7.5 hours of my day! :slight_smile: Thanks for the help.

Hi, is there any chance to do this in BP ?
EDIT : found it : set click event keys (stored as an array).