How to bind timer to specific event in a loop of repeating actions

Hi, all

I use UE 5.3, Windows11, Blueprints

I have “a game” that is in-fact a series of repeating level sequences with different call events on the go depending on the level sequence. It’s an endless loop of like three level sequences, which have each different duration, but work in a loop until quit game.

What I am having is a hard time binding the countdown timer to the event correctly, which means:

  1. I can’t make timer reset to its default integer value (in my case 12 seconds). I am expecting timer to start counting again from 12 to 0 when the loops comes to a sequence where timer is fired up again to start from 12 to 0 over again.
    I’ve set the timer the following way, but when it comes to the level sequence to play countdown time it just shows 00, as if there were already counted once.

After I figure the 1 point out, I am also really struggling with:
Binding duration to the timer.
2. I’ve learned i can get duration of my level sequence if i drag it as an asset into the editor and then reference it in level blueprint, so my delay is synched with sequences switch, but… how can I apply similar formula to my timer? Which means can I get duration from level sequence and bind it to my timer, so it countdowns to the next level sequence switch? (12-0)

I am still very new to Unreal Engine, but persistent and trying to combine virtual production technics, so I am sorry in advance for noob stuff…
I am sure, the above things mentioned are like piece of pie and solution lies somewhere on the surface, just cant see it, lol. Please, help
Any help on the above would be greatly appreciated!

Kind regards,

Hey @skeletronicus!

If StartCount is only called when you want to reset and start the counter, you can set your “SecondsLeft” and “MinutesLeft” Integer variables on StartCount, before the “SetTimerByEvent”! :slight_smile: (See Pic)
image

If all of this is in the same blueprint, you can set the time of the sequence as a variable, and then input that into the “SecondsLeft” area. If it’s more than 60s, you can then divide that by 60, get the remainder and input those two numbers into minutes left and Seconds left!

Hope that helps, let us know if you need more guidance here!

1 Like

Hey, @Mind-Brain!

Thank you for your reply.

I was trying to redo the nodes according to your suggestion if I’ve understood that right:

Now, it would just go one digit down, as it it was counting minutes, however I tried to keep the hierarchy as it should be without changing the other stuff - just created new integers as you’ve suggested:

UnrealEditor_vU4NqKmIcM

This is how I fire up the event in level blueprint, i can see variables there, did I miss something?

Thanks in advance

Sorry, I must not have been clear enough- go back to the way it was in the first picture, I was saying you need to put two set nodes between start count and set timer by event, I can’t doctor the image enough because of the small space:


This sets the initial values of the variables, but keeps them modifiable, which obviously you need as they need to change every second or 60 seconds.
The problem with using this:

Is that this number will only have it go down one time, as this number remains static and is only passed in one time- and you need to reuse it after the change. So if it’s ten minutes, it’ll be 10-1, 10-1, 10-1, when you need 10-1, 9-1, 8-1, which is how you had it set up before.

Hi again, @Mind-Brain !

This time I got you right and it works like it’s supposed to! Thank you so much, I’m learning every day!

Here’s the final working blueprint with your suggestion:

Would you mind if I come back to the second part of my question? Duration of the sequence value passed to the timer.

I was trying to organize stuff like Feng shui, so my repeating events (sequences) are referenced directly to level blueprint and operated from there:

Counter is my Custom event that I blueprinted in BP_Playercontroller class:

All other logic of timer passing its value to widget text is also in widget blueprint.

How do I correctly transfer duration value from my level sequence into bp_controller? OR should I transfer timer blueprints into level blueprint so that they communicate directly?

Thank you one more time!

Okay! This part will be easier.

On your BP_Controller, make a new function. Call it F_SetTimer.

In that function, add an input by first compiling it, and then clicking the starting node and then going to details on the left side. Make the input a float, this is where the seconds go into the function from the level blueprint, so name it “Seconds In”.

Next add “SET SecondsLeft” and “SET MinutesLeft” nodes, and connect the white execution line from the start. We are removing the ones we just placed, and putting them here instead for them to be set from the level BP.

In order to set minutes and seconds effectively, we’ll use the node “Division (whole and remainder)”. Take your float input named “Seconds In” and plug it into the dividend, with a divisor of 60. The remainder needs to plug into the “SET Seconds” and the Return Value goes into “SET Minutes”. It looks like this:
image

Go ahead and delete these, as we are going to do this in the function:
image

Lastly, add “F_SetTimer” to the level Blueprint right BEFORE “StartCount”. Drag off of “As BP Player Controller” like you did before, and have it run “F_SetTimer”. For the input of seconds, use the “Qualified FrameTime To Seconds” float as the input so it is guaranteed to match your delay up above.
image

That should be it! Let us know how it goes!

Cheers, @Mind-Brain!

You were absolutely correct, I’ve done everything exactly to your instructions and it’d worked the exact way I wanted, thanks a bunch!

For future references this is final function blueprint and level blueprint:


Looking into my level blueprint pipeline… does it give you a feeling it requires optimizing? (less nodes to achieve the same result). I am trying to sort things with BP’s, but can my lvl bp pipeline stay as it is or it needs some organizing? Thanks in advance, this information would be very valuable to me from the point of view of my background, as I’ve never been into maths :smile: and visual programming…

Final question, if possible, related to attaching the timer to my progress bar, so it depletes accordingly with timer - How could I do that? Is that a WB i should use and widget animation variable and play function? What is the best way to connect these three things in order to create beautiful time trinity? :smiley:

Honestly, feel super bad about asking basic questions you have already answers for…
But I take my chance and go for it!

Have a great day,

Well this will require some jumping around.

First, you need a “Maximum time” float on your BP_Controller. You’ll need that to remember the maximum time. You can set that in the “F_SetTimer” function you made, with just the input so you have the total max seconds.

Next, you’ll select that progress on your widget designer and create a new binding for it.

In this function you want to use “GetPlayerController” and then Cast to BP_PlayerController. Right Click the cast, and click Convert to Pure function (this makes it green. Green(which means Pure) functions are used when you need to change nothing on the cast object, just get info.

Using the “As BP_Player Controller” you’ll get your Max Time, Seconds Left, and Minutes Left. Multiply the minutes by 60 and add it to seconds Left (basically undo the division from earlier for the widget to get total seconds).

Lastly, you’ll use a “%” node with MaxTime plugged into the top and the total of (SecondsLeft+(MinutesLeft*60)) on the bottom. Take that and plug it into the final purple node on “return Value”.

Let me know how that goes and if you hit any hiccups! :slight_smile:

Thanks.

It was a bit tricky, I am not sure if I’ve understood all correct. I did this in my f set timer function:

I tried different options, but it won’t work the way it’s supposed to :confused:

This is my WB maths binded to progress bar %

However, I get this when play in editor:

UnrealEditor_5owQwJihDw

Did I miss something?

Thanks in advance,

The main thing I see is that the % node is flipped:
image

Max should be in the bottom connection and remaining should be in the top.

Also, try putting a branch in to check if the cast is going okay.

I’m thinking the cast may be the issue but I’m not sure. Check that, and if it is returning False, make it an impure function again and put it in the execution line and see if it’s still returning false. :slight_smile:

Still no luck :frowning:

I did few options, this way progress fill color bar doesn’t appear at all. I tried the branch too. In both cases (impure bp_controller node) in execution line and impure cast I set to FAILED to print string, but nothing appears on the screen at all…

Are there any other ideas left&

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.