I have a date and time system setup using the UE sun system.
I’d like to detect when a new day (eg midnight) is passed. But I don’t want to hav ego check at every tick. What’s a better way to get this info?
Thanks in advance!
I have a date and time system setup using the UE sun system.
I’d like to detect when a new day (eg midnight) is passed. But I don’t want to hav ego check at every tick. What’s a better way to get this info?
Thanks in advance!
If your time doesn’t change/scale or get distorted, then you can just use a timer that fires every time the day changes. In case of Save you will need to store the remaining time of this timer and then on Load you need to resume the timer.
If your time gets distorted, then at some point in time you will need to check it. How often do you change the variable that contains the date? Near that code might be a good spot on where to place this check.
If you are using C++, such code shouldn’t leave a big footprint, even if it runs at every frame. However, you can reduce the interval, and check that every second (or every 5 seconds or every minute), depending on how fast a day is in your game.
If this is not what are you looking for, can you provide more information about your system, so I can better assist you?
Hi @FSapio
Thank you for the fast and detailed reply. You ask some good questions.
The speed to change days is user controlled and spans a wide range of time. So with a flick of the mouse they could be going 1000 days back or forward. It’s pretty extreme. The user changes days very often too – it’s a core piece of the experience.
C++ is probably the ideal method as you mentioned, but right now I’m in BP. Eventually moving to C++ might happen.
Thanks again for the help. It is much appreciated and I hope you are well.
Then, I’d say that checking every tick is a cost you have to pay for your experience, since the change of day is core in your game (and not linear). I mean, Tick functions exist because in rare/specific cases, if you really cannot find any other alternative, you should use them.
Remember that you can adjust the Tick frequency, and consider making a small C++ function very simple that performs this check for you, even if the rest of the project is in Blueprint.
If you give me your current code, I could try to convert it to C++ for you.
Hi @FSapio. Sounds reasonable, thank you again. I am completely BP right now, but hoping to move to C++ in the distant future. I appreciate the offer, though! That is very kind of you.
Cheers, and stay safe!