I want to make an online WebGL game with Unity with button based interaction.

So far I have my login and registration system, with some tables in MySQL to deal with that kind of stuff.

Next I need to deal with timed events.

In the game, you will start a mission just by pressing a button then you will wait a bit, like ten minutes.

How can I implement this wait?

Should I write a waiting routine in PHP, or use MySQL scheduled events? If using events, how many scheduled events can MySQL handle? Or should I use another server-side solution for that?


1 Answer 1


Unless you want your server to initiate some immediately-observable action at the end of the 10 minute wait while the player is offline, then there's no reason to track the timer on the server side at all.

Instead, just save a timestamp of when the button was pressed.

If the game later tries to perform an action that they're not supposed to be able to do while waiting (eg. collecting mission rewards early, or pressing the button a second time), first check the current time versus the last-pressed timestamp, and abort if the attempt is too early.

Now any realtime timer-tracking can be done in your Unity game. When you press the button, start a timer in your client-side script. When that timer completes, you know it's time to update the game state or call the server to ask for the result of the action.

If the player closes the game/browser while the timer is running, no problem: on start-up, just ask the server for any outstanding actions. It can report back the time left on any timers, or any actions that completed while you were away, and you can update the in-game state accordingly.

This helps your game scale better to large numbers of users, because your server is only ever storing/comparing/reporting data on request — it doesn't need to do any continuous background processing for every active player.

The exception is if the game action needs to trigger a result that's observable without the player running your game — like sending a push notification to their phone, or modifying the state of someone else's game who might be online now. So, to ensure your game can scale to large numbers of players, ensure you limit your use of features like this, or find ways you can process them in batches so you don't have to run independent simulations for everyone.

  • \$\begingroup\$ I really didn't think about timestamps since i don't have a lot of experience in mysql. In this case, it looks i should create a mission table with timestamp and other datas pre-calculated when button pressed then when time is up, update the changes i think. Thanks for the answer i get it now. The idea of having huge amount of events was scared me a bit. \$\endgroup\$
    – Somberlain
    Commented May 7, 2019 at 14:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .