How do I use OnBeginCursorOver?

I’m trying to use OnBeginCursorOver to see if I’m over a square.

I have this setup:

.h

	UFUNCTION(BlueprintNativeEvent, Category = "Collision")
		void OnCursorOver(UPrimitiveComponent* Component);

	UFUNCTION(BlueprintNativeEvent, Category = "Collision")
		void EndCursorOver(UPrimitiveComponent* Component);

.cpp

BoxProx is a UBoxComponent here

	BoxProx->OnBeginCursorOver.AddDynamic(this, &AFloorZone::OnCursorOver);
	BoxProx->OnEndCursorOver.AddDynamic(this, &AFloorZone::EndCursorOver);

.cpp part 2

void AActorlol::OnCursorOver_Implementation(UPrimitiveComponent* Component)
{
	pawnlol->DebugMsg("Cursor OVER");
}

void AActorlol::EndCursorOver_Implementation(UPrimitiveComponent* Component)
{
	pawnlol->DebugMsg("Cursor NOT over");

}

The BeginCursor never actually fires.

You need to set bEnableMouseOverEvents to true in your PlayerController. BoxProx must also have its ECC_Visibility channel set to Block.

1 Like

Hi Shohei, unfortunately this did not work for me on my multi-mesh character.

My player controller

bEnableMouseOverEvents = true;

GameUI->SetVisibility(ESlateVisibility::SelfHitTestInvisible);
GameUI->SetVisibility(ESlateVisibility::HitTestInvisible);
UCanvasPanel* canvas = Cast<UCanvasPanel>(GameUI->WidgetTree->RootWidget);
			if (canvas)
			{
				canvas->SetVisibility(ESlateVisibility::SelfHitTestInvisible);
				canvas->SetVisibility(ESlateVisibility::HitTestInvisible);
			}

My character

Head->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block);
....
Boots->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block);

Is there anything else to try?

Thanks!

Is BoxProx the absolute outermost component (spacial-wise)? If it isn’t the MouseOver will be consumed by the first overlapping component and your MouseOver events will not trigger.

Once again, BoxProx must be set to ECR_Block, not your mesh components. If you have a CapsuleComponent and it extends further outwards than BoxProx does you should attach your MouseOver detection to that instead.

Hi Shohei, thank you very much for your reply!

I am not the original poster, I sort of hijacked the thread because it just happens I have the same issue as the OP, in my case I’m using multi-mesh, not static meshes, but your CapsuleComponent Idea was perfect, and now it works as expected. I’ll play around a little bit, but you definitely pointed me in the right direction ( actually gave me the correct answer straight up :slight_smile: )

Thanks again very much for your help!

Oh, didn’t even notice you were a different person. Regardless I am glad to see you are on the right track.