So I just started learning UE. I code games for myself and fun.
Never used blueprints before in any coding.
Normally i can put in “wait(10000)” or “delay(10000)” to delay the code in other languages i used but with blueprints, “event tick” seems to be my “loop” and i can’t stop it from sending signals non stop.
I basically made a timer and want to change texts on my widged for some AI conversation.
“hello how you doing”
delay(1000)
“I am doing great”
but even tick updates the code non stop, is there a way to set event tick to send only 1 signal and stop sending afterwards?
I can probably put a boolean at the end of every “if” but that would mean “A LOT” of “did this random text A already triggered?” booleans for every conversation I will make.
I am asking if there is a better, easier way to make a passing conversation with a timer. Thanks
Yes, Unreal does not allow you to block the running thread, because that would block user input and rendering – the engine needs to re-draw the screen for each frame, no matter what.
The solution to this is to use “state machines” and “unreal timers.” You can google for those terms for more details, but briefly:
Create a variable of type Timer Handle.
When you want to say the first thing, say the first thing, then call Set Timer By Event, and assign the timer handle to the Timer Handle variable.
The event passed into Set Timer By Event, should be a custom event that says the second thing.
Once your system gets a little more complex, it may be hard to keep track of all the different deferred timers you’ll need for this, which is where formalizing the flow using state machines will help. But start with a timer, and see how far that takes you!
Remember to cancel the timer if whatever condition started it suddenly cancels, like someone being removed from the scene, btw. It’s often better to put the pending action in a timer on the action that it’s pending on (e g, “Bob” knows that “In 3 seconds, I’m supposed to say ‘hello’”) which means that, if Bob suddenly dies, he’ll never say hello.