I am trying to bind a function to onclicked with:
OnClicked.AddDynamic(this, &AChessPiece::OnClick); // <- In AChessPiece's constructor
I have declared OnClick in the ChessPiece.h
UFUNCTION()
void OnClick(AActor* TouchedActor, FKey ButtonPressed);
Defined it in ChessPiece.cpp
void AChessPiece::OnClick(AActor* TouchedActor, FKey ButtonPressed)
{
UE_LOG(LogTemp, Warning, TEXT("Clicked"));
}
When I am playing in editor and click on the object I get no response. I have made sure that in the player controller class all mouse events and functionalities are enabled. At one point it was working but has since stopped. Are there other settings in the editor, gamemode, etc. that influence the "Click-ability" of the object?
Don't bind it in constructor. You don't have completely initialized object, so it doesn't make sense. Override BeginPlay()
method and call that binding there.