Call function from Custom Event

If I understand correctly, custom events run asynchronously, whereas functions do not.

So if I call a custom event, then from within that call a function, does the function run on the same thread as the custom event, or does it run on the main game thread?

No, events are synchronous as well. What you’re probably thinking of is that events can use latent nodes (e.g. delay), whereas functions cannot.

A function called on another thread runs on that thread; it wouldn’t be “asynchronous” if the function ran on the main thread.

If I google ‘ue4 events vs functions’ what comes up is ’ Events cannot have return values or local variables like the Functions but the key difference is that they are asynchronous by nature, this means a couple of things: You can manipulate time inside events (e.g., delays or timelines) You can replicate them over network, essential for any multiplayer game.’

I’ve read in several places that events are asynchronous, so it is surprising that you say they are not

I tested it using a long for loop after a delay node: it freezes the game (i.e. the main thread); asynchronous functions do not freeze the game. Events can call latent/asynchronous functions, but events themselves are not asynchronous. A latent function simply pauses the execution of the event until the function is complete.

If events were asynchronous, they wouldn’t be useful for gameplay code because the time they would complete would be random.

1 Like

I’d like to see someone else chime in here. Everywhere I’ve read about custom events says they are asynchronous

Here’s someone who experienced a problem because of this misconception, and a staff member answered the question: https://answers.unrealengine.com/questions/548030/calling-custom-events-consecutively.html. Also, nowhere in the documentation does it say that (custom) events are asynchronous: Events | Unreal Engine Documentation, Custom Events | Unreal Engine Documentation. You can always test it yourself.

This seems to be entirely what the source means by asynchronous. It just means nodes in the event graph can pause and keep executing in frames where they aren’t explicitly called by other game code. It has nothing to do with concurrent execution of multi-threading. The Blueprint VM runs only in the game thread.

ok thx guys for clearing that up

1 Like