I’m trying to create some kind of inventory system. Players should be able to select which item in the world they want to pick up by hovering over the item with cursor. In order to check out how OnBeginCursorOver works I created an AActor-derived blueprint with a few nodes that should print a message when the item is being hovered:
This blueprint had a StaticMeshComponent set in blueprint defaults and everything worked as expected.
Then I tried to implement the same behavior in my AWorldItem C++ class.
In the header I added:
UFUNCTION()
void UpdateOutline(AActor* actor);
And in the source:
void AWorldItem::UpdateOutline(AActor* component)
{
UE_LOG(LogTemp, Error, TEXT("The item is hovered!"));
}
Then I try to bind this function in the AWorldItem constructor:
AWorldItem::AWorldItem()
{
PrimaryActorTick.bCanEverTick = true;
MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
MeshComp->SetupAttachment(RootComponent);
OnBeginCursorOver.AddDynamic(this, &AWorldItem::UpdateOutline);
OnEndCursorOver.AddDynamic(this, &AWorldItem::UpdateOutline);
}
MeshComp here is a UStaticMeshComponent and its mesh is being set after the construction.
So, when I hover over the AWorldItem’s MeshComp nothing happens. MeshComp has valid collisions, my player can collide with it. My UI widgets are invisible for mouse event, the AActor-derived blueprint proves that.
I’m stuck here although I followed others’ examples. What do I do wrong?