I’m trying to implement Custom touch events with C++. Here is what I’m doing:
The header file:
UFUNCTION()
void CustomTouchBegin(ETouchIndex::Type type, UPrimitiveComponent* TouchedComponent);
UFUNCTION()
void CustomTouchBegin2(ETouchIndex::Type type);
and the implementation file:
//in the constructor of my actor Class:
BoardMesh->OnInputTouchBegin.AddDynamic(this, &AMyBoard::CustomTouchBegin);
OnInputTouchBegin.AddDynamic(this, &AMyBoard::CustomTouchBegin2);
//The two events:
void AMyBoard::CustomTouchBegin(ETouchIndex::Type type, UPrimitiveComponent* TouchedComponent) {
GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Blue, TEXT("Somebody touched me"));
}
void AMyBoard::CustomTouchBegin2(ETouchIndex::Type type) {
GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Red, TEXT("Somebody touched me"));
}
The CustomTouchBegin2 works fine, and the message appears whenever I touch any component of the AMyBoard class. However the CustomTouchBegin which is supposed to display a message whenever the BoardMesh, (static mesh) is touched is not working.
Besides the above implementation I derived a blueprint class using the AMyBoard as parent and added the PrintScreen node to the OnInputTouchBegin(BoardMesh) node within Blueprints. That also works.
How can I implement the touch events on specific components using C++?