
Can I break or cancel a delay node?
Technically you can’t cancel or break a delay node unless you’re using C++. But there is a way to re-route the delay node, so it triggers different actions. This requires the use of switches, bools and other nodes that in all intent and purposes will break the delay node.
Below is an example of a Blueprint I created that didn’t work as required, for the delay node needed to be canceled in certain scenarios, but after some additional logic I got it working as required.
Auto Light – On or Off: Initial Blueprint.
I’d created a simple ‘auto – on or off’ blueprint where if the player entered the (begin overlap) collision box it turned on a light. The light would then be triggered to turn off when leaving the (end overlap) collision box. To make this a little more realistic I added a delay node to stop the light turning off immediately. See code below:
The components added for this are just a point light, collision box and a static mesh for the lamp shade.
The problem I encountered was if I quickly re-entered the collision box before the delay was executed, the light would turn off with the player character still in the collision box. Hence leaving the logic functioning incorrectly.
The simple solution would be to just cancel the delay, but there is no way to do that in Blueprints.
Auto Light On or Off: Updated Blueprint with more advanced Logic:
So, I created a switch and branch to circumnavigate the delay if the player re-entered when the delay was still counting down and if the light was still on.
To do this I added a switch (Boolean variable) where if the player re-entered the collision box whilst the delay node was still running, this would flick a switch to re-route the delay node to keep the light on, as opposed to turn the light off. See the final version and a detailed outline of the code below:
Logic: The > arrow represents the flow of the nodes in the graph above.
- Player enters the (Begin Overlap) collision box > Triggers the Branch.
- Branch Condition: I added the Is Visible node > The target of this is the point light and this checks if it’s Visible.
- I created a Boolean Variable and called it: Stop Auto Off
- So, if Light is Visible > Then the Branch = True > Set Boolean Switch (Stop Auto Off) to True (as its set to False initially)
- If not visible > Then Branch = False > Set Visibility to Visible (tick the box).Â
- Branch Condition: I added the Is Visible node > The target of this is the point light and this checks if it’s Visible.
- Player leaves (End Overlap) collision box > Triggers the Delay.
- This Triggers another Branch.
- Boolean Condition = True or False
- If True > Set Visibility to On and Set Stop Auto Off to false (by default leave the box unticked in the Boolean node).
- If False > Set Visibility to Off.
In summary:
When the player enters the collision box it checks if the light is on (visible) if it is on then flick a Boolean switch and this will simply change the action for when the player leaves the collision box. Hence, either trigger the delay to turn the light off when the player leaves or if the player remains under the light then keep the light on!
Key Notes:
This is one way to re-route a delay node and you may have to tweak or amend the logic for your purposes, but this should give you a way forward. If you have any comments or suggestions please do say.