x

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"

How to execute C++ timer even when the game is paused?

I'm currently programming a playtime tracker in C++ that supposedly keeps increasing even when paused, due to the playtime variable only shown in the pause menu. However when pausing the game through the character blueprint, the timer in the C++ code is also paused.

AFAIK, this was because Game Pause function pauses the global time dilation too, thus affecting the timer which is called using GetWorldTimeManager().

Is there any workaround or alternative function for the timer? I avoiding Tick because the tracker requires precision down to 10 ms (0.01 s), which is faster than stable 60 FPS frametime, and can cause imprecision on slower frametimes (delta secs).

Product Version: UE 4.20
Tags:
more ▼

asked Mar 15 '19 at 12:16 PM in C++ Programming

avatar image

The Hoodie Guy
10 1 4 6

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

1 answer: sort voted first

This doesn't directly answer your question as stated — I'm not sure how to prevent the Timer Manager from being paused when the game is paused — but this is hopefully a solution for your needs.

Why not use UWorld::GetRealTimeSeconds() to store the real-world time when the game session starts, and call that function again whenever you need to update (and display) the session's elapsed time to the player?

Just do something like

 float ElapsedSessionTime = GetWorld()->GetRealTimeSeconds() - SessionStartTimeSeconds;

...to update how long the session has been active. Your pause menu can use this updated variable to always display the current, accurate elapsed time.

(That example assumes you have a variable called 'SessionStartTimeSeconds' which you would set when the session starts, e.g. in some BeginPlay() function somewhere.)

Hope that makes sense. Good news is, it should be really easy to get working, even if my explanation is bad.

more ▼

answered Mar 15 '19 at 05:21 PM

avatar image

the_batch
1.2k 4 5 8

(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