Trigger Event if Crosshair Hovers for Several Seconds

I have been using line traces to hit and object in my scene, then trigger an event. Currently I have it set up if I put the object in my crosshair and left click, then it will trigger the event. Or using Event Tick, if the crosshair overlaps the object, it will trigger the event. Is there a way to only enable the event if the crosshair overlaps the object for say 2 seconds, then trigger the event? Or if the crosshair moves off of the object in under 2 seconds, then the event doesn’t fire? The idea is to create a VR interaction without the need to click any buttons. So look at a target for 2 seconds, and trigger, or look away and cancel the trigger event.

I know that is an old issue, but I’ll leave my solution here in case anyone needs this. :smile:
If i get it right, you can do it by using the delay node (for blueprints) or FTimerHandle (for c++). Once you start a timer in UE, you can’t stop it, so I think the best way to handle your problem is create a bool variable that starts with false value and when the crosshair starts the overlap, set it to true and starts the delay. If it ends the overlap, you set the bool variable to false. After the delay, you can call your function if the bool variable is true.
In blueprints will be something like this:

and in c++ will be something like this:

bool bTimerEnded;
void AMyActor::OnBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
    // Declare a timer handle as a member variable
FTimerHandle TimerHandle;

// Start the timer with a delay of 2 seconds
GetWorld()->GetTimerManager().SetTimer(TimerHandle, this, &MyClass::DelayedFunction, 2.0f, false);
}

void AMyActor::OnEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
    bTimerEnded = false;
}

// Implement the function that will be called after the delay
void MyClass::DelayedFunction()
{
    if(bTimerEnded)
    {
       //call the desired function here
    }
}