What happens if an event is called while already running?
For example, imagine I have a custom event called DoSomething that takes 10 seconds. Imagine it gets called 1 second after the game starts and then called again by something else 2 seconds after the game starts. I can imagine a few possibilities:
Each event call generates its own scope and runs separately without interfering with the other.
Once the second call do DoSomething fires the first one immediately terminates because there should only be one verison of an event processing at a given time.
I’m guessing it is #1 but would like to verify and learn if there is anything else special about events.
One reason I ask is because some things like timelines can only be used inside the event graph and not in macros or functions.
I think #1 is more reasonable.
But I try to use “delay” to simulate this situation and find out that maybe #2 is right.
It’s weird.Hope ue staff can explain it.
I actually didn’t know the answer but… the only way to get smarter is to check it out!
So let’s do that. What do we want to test?
Does calling an Event a second time interrupt the first execution if it’s still running?
So how shall we do that? Well let’s just create an simple setup that only checks exactly that. A new custom event, two print nodes, a delay between them. On Event Begin Play I call the event, wait half the time the other delay takes and call it again.
So what do we see? There is two Hello1s before one Hello2 and then the “Test finished”.
So the conclusion is: The event will be run again from the beginning if a new signal is provided and the old execution will be stopped.
WRONG WRONG WRONG!!!
Yay for year late updates.
“Delay” is causing this behavior and “consumes” the second print because it didn’t run through yet.
In regular non time based code the execution is safe.
There is no instancing of events or anything along those lines. Meaning practically speaking, exactly the same line of execution is called again.
Whatever you did before will still hold true. Do Once, Delay, Gate all keep their states. So does everything else you might’ve changed.
It’s not interrupting the execution. Rather, what’s happening is that the Delay(2) node in Test is ignoring the second execution pulse. This is indicated in the tooltip for Delay. It’s counter-intuitive, but that’s how it works.
I was wondering how this effected a Timer to see whether I could have a Timer running an event loop multiple times. Result: 1 is Printed until 1Key is Pressed, Original Execution becomes invalid and only 2 is printed. (v.4.17)