Using a delay in C++

Delays are considered latent functions in unreal terminology. Basically they should not block the main execution thread and run aside it as a seperate thread.

I suppose unreal only supports them in Blueprint editor via Events. The engine has a complex mechanism that converts Events to threads whenever they include a latent function node (like delay) in their call graph.

The Events created in unreal blueprint editor (red nodes) do block the main execution thread unless they include a latent function like the Delay node in them. So they are no different then Function without a return value unless they include latent nodes.

If they include latent nodes however suddenly the magic happens and they become threads.

On the contrary Functions created in blueprint editor (purple nodes) will always block the main execution thread no matter what.

Check my own question about this issue which I eventually answered myself:

So the code you have called in your C++ method is designed to be called from the Editor not from C++ side.

To achieve the same effect on C++ side the easier solution I believe is to use timers or your own thread implementation (see FRunnable).

The easiest solution however (though not performance friendly) is to expose a function to the unreal editor (BlueprintImplementableEvent or BlueprintNativeEvent) and override it so that it uses your Delay node. Whenever you need a delay you can call this blueprint function from C++ and when it time outs it can return back to the C++ code through a call to a C++ implemented BlueprintCallable function.