In my game, some values changes every day. When a player launches the game, I send a request to the server and retrieve the values. Those values might change while the player is playing the game, so I’m thinking of making a timer to check if the local time reaches a specific date. Is there a way to make a timer that fires an event?
I’m looking for something different than making a float number and running in an Update function. Because the next update time might be 8 hours later for example. I’m looking for something that runs on the background silently(!) and when it hits the zero or its fire time comes, it fires an event.
Why!!! You do understand that’s all a timer does, right?? Same goes for a timer implemented in your code, in the Unity engine, in the operating system, or on a remote server. There isn’t any other way. It’s not like there’s a magical “timer command” you can set and then it magically calls you in the future without any CPU involvement ever agai… that is just not a thing on general purpose computers until you get down to the OS driver level. And you do not want to go there.
That’s all the OS is doing for you when you set a time alarm to get notified in the future. That is all an invisible GameObject with a CallAfterDelay script is doing. Here’s a link to one I use:
If you’re looking for stuff to happen when your app is in the background (or not running at all), that gets into using the operating system to wake your app up in some way. On iOS and Android that mechanism is called a push notification and there are a bunch of youtube tutorials for them. For the PC and Mac targets I’m sure there is an OS-level alarm you can tap, but again, like push notes it will live outside of Unity.
Of course, I cannot escape CPU consuming. I understand that, but I came from Unreal Engine, and it has a timer feature that you set the timer and it calls a callback. It doesn’t run in the game thread. I was wondering if in Unity, there is something similar to the Unreal Engine’s timer.
Other solution could be async-await functions but I don’t want to get into that.