I’m trying to get a function to execute when the cursor overlaps a box component on an actor. It hasn’t worked at all under normal conditions. However, it does work under non-normal circumstances: the player must be standing inside a component of the actor to get cursor overlap events to work. If the player is standing away from the object and not standing within any of the object’s components, it seems the cursor overlaps are not recognized. The code I am using is below. What could be causing such a problem?
In player controller constructor:
bEnableMouseOverEvents = true;
In actor’s header file:
UPROPERTY(EditAnywhere, Category = Testing)
UBoxComponent* BoxComponent;
UFUNCTION()
void MouseOverFunction(class UPrimitiveComponent* OtherComponent);
In actor’s constructor:
BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxComponent”));
BoxComponent->AttachParent = TheParent;
BoxComponent->OnBeginCursorOver.AddDynamic(this, &AMyActor::MouseOverFunction);
Later in actor’s cpp file:
void AMyActor::MouseOverFunction(class UPrimitiveComponent* OtherComponent)
{
UE_LOG(LogTemp, Warning, TEXT(“Cursor has begun overlapping box component.”));
}
If I do not use the code above and instead simply override the NotifyActorBeginCursorOver to print a message to the log, the same behavior is still seen: the player must stand inside one of the actor’s components to execute cursor overlap events for that actor. Also, the problem persists even if objects and components are separated far from one another to ensure that nothing else is blocking the component that the cursor is over.