OnClicked event doesn't fire when camera angle changes

I am working on a project based on the sidescroller C++ template.
At some points, the mouse cursor is visible and you are supposed to select objects by clicking on them.
For the selection phase, the camera moves and rotates to have a top-down view of the area.

I implemented the OnBeginCursorOver, OnEndCursorOver and OnClicked events on the interactable object in C++.
These 3 events only write messages in the console for now.
I also added blueprint OnClicked node that writes “Click BP”, to track down the origin of my problem.

Everything works fine when the camera is at its original rotation. On the bellow image (I couldn’t upload a gif of that problem that is < 5.2MB…) you can see that every event writes the desired message in the console.

However, after a camera rotation to get the top-down view, this started acting weirdly. The OnBeginCursorOver and OnEndCursorOver event still were triggered, but not 100% of the time. And the OnClicked event didn’t work at all. Even the blueprint version.

Here is the .cpp of my clickable actor:

 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	CustomMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Test Component"));
	RootComponent = CustomMeshComponent;
	CustomMeshComponent->OnBeginCursorOver.AddDynamic(this, &AClickableActor::CustomOnBeginMouseOver);
	CustomMeshComponent->OnEndCursorOver.AddDynamic(this, &AClickableActor::CustomOnEndMouseOver);   	

// Called when the game starts or when spawned
void AClickableActor::BeginPlay()
	CustomMeshComponent->OnClicked.AddDynamic(this, &AClickableActor::CustomOnClick);

// Called every frame
void AClickableActor::Tick(float DeltaTime)

void AClickableActor::CustomOnBeginMouseOver(UPrimitiveComponent* TouchedComponent)
	UE_LOG(LogTemp, Warning, TEXT("Mouse Over !!!!"));

void AClickableActor::CustomOnEndMouseOver(UPrimitiveComponent* TouchedComponent)
	UE_LOG(LogTemp, Warning, TEXT("End Mouse Over !!!!"));

void AClickableActor::CustomOnClick(UPrimitiveComponent* ClickedComp, FKey ButtonPressed)
	UE_LOG(LogTemp, Warning, TEXT("Click C++"));

A couple more precisions:

  • The OnClicked event is created in the BeginPlay, otherwise it just never worked.
  • I tried with various camera angles. As long as the camera is not at its original angle, the click event always fails.
  • I tried putting the camera at different distance from the ground thinking, maybe the clickable object was too far, it also always fails.
  • Finally, in the PlayerController blueprint, I off course did all that after activating “Enable Click Events” and “Enable Mouse Over Events”. I also tried to change the trace channel and trace distance, which didn’t help.


Any idea what could cause this problem?