Delay interacts badly with destroy actor

I think there is a bug in how delay works.

If you call “Destroy Actor” in a blueprint, any subsequent Delay nodes will cause the blueprint to stop execution. To replicate this, use the blueprint shown below. Note that string “testbug after delay” will not be printed (in UE 4.7). If you remove the Delay node or the “Destroy Actor” node then that string will be printed.

My guess is that Delay is somehow calling back to the actor or blueprint but if it is destroyed then the callback doesn’t happen. This can be quite confusing and hard to figure out what the issue is.

I would suggest some of the following options to fix the bug:

  1. Make it so that Delay can work with “Destroy Actor” as verified by the string “testbug after delay” being printed by the blueprint shown.
  2. In the documentation for Delay, provide a note saying that it won’t work if you call “Destroy Actor” before Delay.
  3. If Delay is called after “Destroy Actor”, generate some kind of error message indicating the problem.

Thanks,

Hey -

What seems to be happening is that the call to the Destroy Actor node is happening but the destroy event isn’t happening for a frame or so. Without the delay, everything after the Destroy is happening in the frame that the actor still exists before being destroyed. The delay causes the next frame to trigger at which point the actor no longer exists to execute the rest of the blueprint. This has been bugged (UE-10329) for further investigation.

Cheers

Thanks for putting into your bug tracking system. Am I supposed to mark as resolved now that you have filed a bug on it or leave open until bug is fixed? Either fine with me; just trying to learn appropriate bug reporting etiquette.

Thanks,
-X

After speaking with one of our developers it appears this behavior is by design. Clearing delays on destruction of an actor allow for smoother control flow to prevent crashes later. Since “Destroy” happens at the end of the frame, clean up and other housekeeping can be done within the current execution chain.

Still think this should be documented or show error in editor.

Is there a work around to this. I have a boost that speeds up the actors movement and destroys the boost and after 10 seconds I want to set the speed of the actor back to the original speed?

Hey -

Rather than having the boost reset the speed, I would have the boost set a boolean on the other actor. When the boolean is set to true start a timer as well as change the movement. When the timer reaches 10 seconds, reset the movement and switch the boolean back to false.

Thanks for the idea. I will look at that. Later I approached it another way, instead of handling the speed changes in the boost I added an overlap event to the character and check that the class of the overlap is a boost. Only think I can think is that might be slower than your solution as it is checking anytime it overlaps an object and not just on the boosts.

Any thoughts on that?