I’m having problems with mouse over events on static mesh components via OnBeginCursorOver and OnEndCursorOver and OnClicked.
I have code which has worked over all recent versions up to 4.24.2, but the identical code does not work under 4.25.
The relevant parts are:
[Header file]
UFUNCTION(BlueprintCallable, Category = ViewPoint)
void BlockClicked(UPrimitiveComponent* ClickedComp,FKey key);
UFUNCTION(BlueprintCallable, Category = ViewPoint)
void BlockBeginMouseOver(UPrimitiveComponent* ClickedComp);
UFUNCTION(BlueprintCallable, Category = ViewPoint)
void BlockEndMouseOver(UPrimitiveComponent* ClickedComp);
[Constructor]
// Create dummy root scene component
DummyRoot = CreateDefaultSubobject<USceneComponent>(TEXT("Dummy0"));
// Structure to hold one-time initialization
struct FConstructorStatics
{
ConstructorHelpers::FObjectFinderOptional<UStaticMesh> ViewPointMesh;
FConstructorStatics(): ViewPointMesh(TEXT("/Game/Meshes/ViewPointMarker.ViewPointMarker"))
{
}
};
static FConstructorStatics ConstructorStatics;
// Create static mesh component
BlockMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BlockMesh0"));
BlockMesh->SetStaticMesh(ConstructorStatics.ViewPointMesh.Get());
BlockMesh->AttachTo(DummyRoot);
//React to mouse clicks
BlockMesh->OnBeginCursorOver.AddDynamic(this, &AViewPoint::BlockBeginMouseOver);
BlockMesh->OnEndCursorOver.AddDynamic(this, &AViewPoint::BlockEndMouseOver);
BlockMesh->OnClicked.AddDynamic(this, &AViewPoint::BlockClicked);
[Functions]
void AViewPoint::BlockClicked(UPrimitiveComponent* ClickedComp,FKey key)
{
if (GEngine)
{
FString message1 = TEXT("BlockClicked ViewPoint Called...");
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Yellow, message1);
}
}
void AViewPoint::BlockBeginMouseOver(UPrimitiveComponent* ClickedComp)
{
if (GEngine)
{
FString message = TEXT("BlockBeginMouseOver ViewPoint Called...");
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Yellow, message);
APlayerController* MyController = GetWorld()->GetFirstPlayerController();
MyController->CurrentMouseCursor = EMouseCursor::Hand;
}
}
void AViewPoint::BlockEndMouseOver(UPrimitiveComponent* ClickedComp)
{
if (GEngine)
{
FString message = TEXT("BlockEndMouseOver ViewPoint Called...");
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Red, message);
APlayerController* MyController = GetWorld()->GetFirstPlayerController();
MyController->CurrentMouseCursor = MyController->DefaultMouseCursor;
}
}
I am finding that unlike in 4.24.2, in 4.25, the static mesh does not react when hovering the mouse over it. Also, when I click the left mouse button, the OnClicked event isn’t called. When I release the left mouse button however, both the BeginMouseOver and EndMouseOver events are called.
Has something changed in 4.25?