Download

OnClicked Event Not Firing

In this program, what I want to have happen is for my cursor to be able to lift a block once it’s been clicked. The static mesh component (the block) is part of my MainPlayer character, so all of the code is in my MainPlayer.cpp. So first I create a UStaticMeshComponent called PuzzlePieceMesh in the constructor.

PuzzlePieceMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT(“PuzzlePieceMesh0”));

Then I include the OnClicked event in the constructor as well…

PuzzlePieceMesh->OnClicked.AddDynamic(this, &AMainPlayer::CompClicked);

which should call CompClicked function if my mouse clicks the block

void AMainPlayer::CompClicked(UPrimitiveComponent* ClickedComp, FKey ButtonPressed)
{
UE_LOG(LogTemp, Warning, TEXT(“CompClicked…”));
PieceClicked();
}

However, this function is not being called, leading me to believe it’s a problem with the mouse interface.

I’ve checked to make sure the following was true:

  • Show Mouse Cursor is **true **(Within PlayerController BP)

  • Enable Clicked Events is **true **(Within PlayerController BP)

  • PuzzlePieceMesh has a **static mesh **with collision (Within MainPlayer BP)

  • In project settings->input->mouse properties->Use Mouse for Touch is false

  • Default Pawn Class is MainPlayer BP

  • Player Controller Class is PlayerController BP

  • Default Gamemode is also set correctly

I’m not sure what else to check, so help would be appreciated on how I can get the OnClicked event to fire upon clicking the component. I’ll answer any questions to best of my ability and edit this if I figure it out myself.

Thanks.