How can I add a Countdown Timer to a Level with Blueprints (e.g. Time Limit to complete a Level )

I’m having trouble trying to create a visual countdown timer with Blueprints. As I’m not sure where to start with it.

I’m trying to create a timer that can be placed into individual levels, and will display on the Player’s HUD, the time remaining to complete a level.

(The reason I’d like it to be placeable and editable into different levels is that different levels will have different times required to complete them).

What I’m aiming to create is a time limit to complete the level, that displays on the player’s HUD, If the timer hits “0”, then a “Game over” with a “Restart” button appears.

(an example level would be: You must reach a certain point or score a certain amount before the timer hits “0” - Or a game over screen is displayed.)

I would really appreciate any help with this as it’s causing some headaches trying to figure out. Thanks for your time!

Game time seconds - this is your node.
Place it in player controller (as it has easy access to hud and player pawn).
First create timer:

  • we do not use timers that are in inreal for this, they have bit different role.
  • create variable that is float and holds starting thim, lets call it “level_start_seconds”
  • remember game time seconds in that variable, when level starts, or for now easier when node: “begin game” is executed.
  • create next float variable “elapsed_time”
  • now having that, on game tick event again get “game time seconds”, substract from it stored “level_start_Seconds”, store result in “elapsed_time”
  • here you have your counter.

Now displaying counter in UMG: watch and follow some umg tutorial,

  • create text widget, place it where you want timer
  • text widget has text field (that determines what it displays), there is small bind button next to it, create new binding, it will create function. Call that function “display_elapsed_time”
  • in that function. do: get player controller, from it cast to your player controller type. from cast node drag blue pin and type “elapsed_time”, it should let you get its value
  • now add “format” node in “display_elapsed_time” function. Type in: “elapsed time: {t} seconds”, connect “elapsed time” (that one from cast node") to format node.
  • connect result from format to return node of function

You have your timer.
Things that you may want to improve:

  • changind seconds to hh:mm:ss.ss time format
  • doing events for start timer and stop timer

I can sort of follow the pseudo code, but I’m having trouble actually trying to follow your steps, Could you possibly show me with a screenshot of it in blueprint form?

I have a couple extra questions about this way of doing it:

  • Would this still allow me to change the “time limit” to complete each level? For example Level 1 takes 2 minutes to complete, Level 2 takes 3 minutes etc…

  • How can I format the timer to be minutes and seconds?

Thank you so much for replying though! :smiley:

If i have tonight some time i will make screenshot, currently not at my unreal pc.
Watch some tutorials, if you watched them you would have no problem with making this timer.

I appreciate that, thanks. I have watched loads of tutorials, but they always lead to timers counting up and not down, if that makes sense.

Would your method still allow different times for different levels though? :slight_smile:

Up or down is a matter of one more substract (or add) operation.

You get game time seconds when event(timer) started. Add to this time limit (for eg. 30sec).
Then you substract from that value your current seconds, and you have timer counting down.

Yes it allows different timers for different levels. Either make variable in level blueprint that holds level timer, and on begin play “tell” player controller what is limit for this level. Or make array of time limits in player controller, check which level is loaded and pull corresponding value from array.

And. Do not just watch tutorials, follow them and recreate what they do. I know its slow process and quite hard at beginning, but i think you need learn some basics of programming (because your questions are quite simple). And best learning is from making something after tutorial.

I’ve learnt quite a lot, I just got stuck with timers.

I’ll be honest, I’m more of a developer based on artwork than programming, but I’m still trying to make my own game using blueprints. That’s why I asked, but I managed to figure it out eventually.

I was able to create a timer using a “delay” on an Event Tick, for each second it subtracts from a “my time limit integer” which loops on itself. I made the actor placeable into the level, and as such was able to expose and add a construction script that allows a different Time Limit to be set per level, in the editor window.

I used a Compare Int node to find the “0” timer value to trigger a “game over” or fail-state. The only issue is formatting of the Minutes and Seconds. At the moment if I add “100” it will count down from 100 seconds, rather than showing 1m 40s. But it might make my puzzle game more interesting if it’s constrained to 60 seconds. :rolleyes:

I wanted to do it this way because it will speed up the level design aspect, if all I have to do is place an object and tweak it’s values.

Thanks for your help too. If you still fancy showing a screenshot of how you’d do it, I’d be happy to learn from it.

Can you link some of these tutorials?

hi
I also need the same help

Below is a way to create a count down timer instead of counting up. Has anyone found a way to input this into the menu and have it work with the pause resume feature. I have it created but it pulls up on every level I open including my main menu. When I am in a regular level and pause it the timer continues. When i resume the timer disappears. However if I go back to main menu and select the 1st level again the timer restarts. Any ideas on how to have that not happen with the resume and to only show up in levels?