Delay in a Function? Why Not?

Why am I not allowed to use a delay in a function?

My problem is that I can’t achieve that what I want to achieve. I just don’t like the messy BP, that I create to handle this problem.

Is there maybe a trick? How else can I handle this?

Because functions are executed in a synchronous blocking manner. The calling function/event/code waits for the function to complete. Delays can be used in events.


This is an intentional limitation. I have provided a link to an answerhub question that will provide additional information. I have also included a quote from that same page that answers the above question. I hope that this information helps.

Link: Why can't I add a Delay Node to a function? - Blueprint - Epic Developer Community Forums

Quote: "This feature is a design constraint that will not be changed. The reason is that functions have return values, and can be called from native code. Because things can be relying on the return value of a function, we don’t want to break the game thread waiting for that code to finish delaying.

Event Graph has shared state, and is re-entrant. That allows a degree of flexibility, because we’re saying nothing depends on the result of anything. That’s why events don’t have return values, and allow for delays and other latent functions."

Make it a great day

I did it with “Delta Seconds” on a tick event and a boolean. But the tick is constantly firing the event so i dont need to interrupt code to delay in between, i want a delay at the end of the function before it starts again after a certain criteria.
You might be able to do something similar in a non tick event, using a while loop where it keeps adding the delta seconds to a float var and it runs the loop while the var is not equal to the amount of seconds you want the delay to be. Didnt test that way though, i dont like while loops much. but the delay on tick events works if you need to do something with those.

i dont think functions need a delay, especially i dont think you should use it on tick, for me its just a bad design
there are some issues with networking, but they can be handled using input and don’t rely on variable replication.

Use Macro instead.