Want to create a secret timer that will diplay when the player dies

Hello guys! I am very new to ue4 so sorry if this is a noob question. I want to have a timer (not displayed on the screen) that will count the time from when I click the play button to when my player collides with lava (dies). I made the system with overlap with lava so it goes back to the main menu but I want it to display the time alive (can be only in seconds). And if it is possible to later display the best time alive in the main menu (and updates it when a new best time is reached) Thanks in advance!

Ps: I’m working in Blueprints

I made this: Screenshot by Lightshot It works andit prints seconds when I enter the level. Now I just need to know how to diplay that number on the end and how to diplay the biggest of them in the main menu.

i made a little example of one possible way this could be done. note that i would store the values in the game instance instead of the game mode as show below.

the first picture below shows one method to get the time when the player overlaps the lava, its basically what you have but done differently. the difference here is that i then call an event in the game mode and pass the time of the previous run along as well.

the second picture shows the game mode event that we called in the previous picture. we first set a variable LastTime which will hold the time of the previous run. then we want to compare and place the lastTime in the array of the fastest times (the leaderboard). we do this via the for each loop which compares the time of each element in the array to the last time via the the less than (<) operand. if the time of the lasttime is faster then the element its being compared to then we insert the time into that index, resize the array so it stays a top 3, and break out of the loop. we then create the widget and add it to the viewport. this is where it will be a bit different in your case as i have it setup to show all the information at the end of the level / on death.

the last picture shows the widget we created in the last section. here when the widget is created it gets the game mode and casts to its class so we can get the variables it contains. we then just need to set the text objects that will be shown. i used one text object for the the current time and one for each of the top 3. to set the previous runs time i got the lastTime variable and appended some text (your time was: ), then got the text object i wanted to fill and used a set text node. Setting the leader board top 3 is basically the same idea but i used a loop to do the work.

like i said at the start i would do all this in the game instance instead of the game mode since it persists between levels and makes things convenient when saving the game. hope this helps

what is your last time?