How to Cancel a Delay

Hi o/

I often use delays to activate or deactivate a component (like fire) but sometimes it could create some bugs if the actor is reset before the delay ends (for instance, when I simulate the reload of the level, I reset fire to off but if the delay is not finished, is set it back to on).

Is there a way to cancel a delay? Maybe “Task Wait Delay” could help me but i don’t know how to use it…

Thanks :slight_smile:

You can’t cancel a delay.

However, you can start activating/deactivating things based on relevant criteria instead of using “hard” delays (delay x amount of time and praying for the best).

You can’t cancel it, but you can check a condition at the end of a delay and decide whether you want to execute what ever is after the delay

1 Like

You CAN cancel a delay, but you have to use C++. I added a blueprint node that will cancel all pending delays for a given blueprint actor. Technically, it cancels all pending latent actions, not just delays, so it can have additional side effects – careful.

void UNodeLibrary::CancelDelays(AActor *actor)
{
	if (actor == nullptr)
		return;

	actor->GetWorld()->GetLatentActionManager().RemoveActionsForObject(actor);
}
2 Likes

yes, old thread, but since it’s the first to come up when googling…
here’s an example of one possible solution for a common case:
retriggeable_delay is forced to trigger ‘immediately’, which then gets intercepted


comments added using ‘Comment Bubble Assist’ plugin

3 Likes

Oof, this is excellent. Thankyou!

1 Like

You can also put a gate at the end of the delay

1 Like

You saved my life, Thanks!

1 Like

That’s what I needed! The “Retriggerable Delay”. Sovled it all :grin: Idk why it doesn’t come up when you search under Delay :thinking: But yes, Thank You!!!

1 Like