Create an in-game clock

Hi there

So yesterday I got a day/night cycle in my project and then I thought it would be nice to have an in-game clock somewhere. I built myself a widget and I made a blueprint able to show the in-game clock but since I’m using an event tick I’m trying to change the format and I’m a bit in the dark here. So the hour display shows something like “16.78”. I’d like to make to changes to that : first, show a colon instead of a comma and secondo, don’t let the minutes go over 60.

I’m pretty sure I should use the append function to make a colon but I have absolutely no idea how to get the minutes.

Thanks.

Bump. Anyone ?

Can’t seem to figure out how to get the formula for the minutes.

I ended up using truncate and append to have a good hour format b ut the minutes have got me scratching my head.

Would you use the real time or a pre time build in-game. If you’re using the real time you can use the Now function to get HH:MM:SS

Hi. To get an HH:MM:SS format you can store your ingame timer in seconds and using following formulas to get minutes an hours:

M = (S / 60) % 60

H = (M / 60) % 24 - for 24 hours format or

H = (M / 60) % 12 for 12 hour format

Both / (division) and % (modulo) operators existing in BP.

1 Like

You can assign your time variable to a string, then do a replace on your string to convert the decimal to a colon. Then in your tick timer, you can do an if statement to see if its over 60 to put it back to 0

maybe though take a step back and see how others have implemented this - doing this on tick will be really cpu intensive

I googled in game clock on youtube and found some good tutorials for you

https://www.youtube.com/watch?v=95Up5kmlEkQ https://www.youtube.com/watch?v=9N73RxMHXSg

That last tutorial was pretty close to what I already had and gave me some good tips and ideas and I was finally able to get what I wanted. One of the only part I was missing was to multiply my TimeOfDay variable by 60 then divide it back by 60 with divide(whole and remainder) -such a great function that I didn’t know about- to get the minutes and then store them in a variable.