Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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

Product Version: UE 4.19
more ▼

asked Sep 10 '18 at 06:13 PM in Blueprint Scripting

avatar image

1 1 2

avatar image KiWi_9 Sep 10 '18 at 06:31 PM

I made this: http://prntscr.com/kstqyh 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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

alt text

alt text

alt text

capture.png (123.7 kB)
capture2.png (289.2 kB)
capture3.png (299.7 kB)
more ▼

answered Sep 10 '18 at 11:15 PM

avatar image

10.1k 33 10 25

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question