How to manage time-based actions?

Hi everyone! I’m new in the forums and kinda new to Unreal in general and I’m having a bit of a hard time getting to understand how to do some things, for example the topic of this question: how to manage time-based actions?

I’m working on a game where I need to have something happen every couple of seconds (i.e. Hunger meter goes up), but I also need to have the character execute some time-based actions (i.e. Cooking a pizza takes X seconds but cooking a turkey takes Y seconds). Also, some other actors will have their own time-sensitive actions (i.e. Tomato plant will be harvestable every N seconds but will rot if N*5 seconds pass by without harvesting it).

Before we move forward a quick disclaimer: I’m working exclusively with Blueprints, would rather keep it this way but if the only solution is to turn to CPP I will.

I know what I’m describing is nothing ground-breaking, but somehow I can’t seem to find out how to deal with this.
I’ve tried using delays, but this only works on the Event graphs? So I can’t fire a “waiting X time” action in any function that’s not in the event graph.
I’ve tried having an array for all states of an actor that will loop through the array and call event dispatchers that should call other event dispatchers and wait for that before proceding but the loop loops through the entire array in a single frame? (why does it do that? I honestly don’t understand).
I’ve tried Set Timer by Function Name but this only waits before calling a function, which is not really what I want, I want the function to run but spend time running, does that make sense? For example I want the function to print “I’m cooking” and stay cooking for X seconds and then finish.
I’ve tried with while loops, calling functions that return booleans and check those before proceding.

Also I’m trying to manage all this action either in the controller or the game mode, but want each actor to have it’s own information about what actions it can do and how long they take.
And also I want to have modifier that will make the character do their own actions faster and other modifiers for the other actors as well.

I hope this gives you a good understanding of the kind of time-based actions that I need to manage. My question is how to manage all this? What concept am I missing or what blueprint function is the one that I’m not using? Am I wrong in trying to manage this in the game mode or player controller? is there a specific way to handle this sort of stuff?

Any help is appreciated

  • use timers:

  • or looping timers:

This would cook for 10s and report the progress every 2s - you could update the progress bar / display here, for example.

  • or many timers:

The first one keeps track of the overall time, the second one reports the progress 10x per second. The timer handle contains the timer data, you can pause / unpause, see how much time remains and so on.


Also I’m trying to manage all this action either in the controller or the game mode, but want each actor to have it’s own information about what actions it can do and how long they take.

You could script the timer into the class itself. But it might be more convenient to have a component that handles the timers. This components can then be added to any actor that needs time flow monitored.

Hi, thanks for answering. It took me a few days to try out what you did but I seem to still be having problems handling this.

In your examples, you are showing only event-triggered logic. In my case I have a function that process an array of actions (a queue of sorts). For each action in the array, the function should trigger the cooking event of other actor, wait for it to complete and only then trigger the next one.

I can trigger the event of the cooking actor and it does wait, but the processing of the queue just moves on and triggers the next one or it simply stops running because it’s not getting the boolean information of the finished action and just stops