Best method for countdown timer ?

Options
Hi everyone ! How are you ? :smile:

So, I made a countdown timer in my game using RPC calls every frame, and it works perfectly. But I don't think that is the best method to do. Indeed, my script needs so to call many RPC at everyframe.
I tried a system which call one RPC to start a local timing on each client, but this has synchonization problems and/or doesn't start on all clients.

How can I make a better countdown timer ??
I heard about OnPhotonSerializeView, but I don't know how to use it in my case and if it would be usefull.

Here's my script :sweat_smile:


Comments

  • Hi @Gumiho,

    please take a look at the InRoomRoundTimer script that comes with the PUN package. It uses the custom room properties to store the start time in order to let each client calculate the timer on their own. The script is located inside the 'Photon Unity Networking/UtilityScripts' directory. I think that is what you are looking for. If you are looking for another solution, feel free to ask again.
  • Gumiho
    Options
    Hi !
    Thanks for reply, I will take a look at it. If this system pleases me, it's ok, and it will I guess ! ^^

    Is it correct to update timers on each client using OnPhotonSerializeView with current time of master client as parameter ? If yes, is it possible to have a quick example ?

    Thanks you ! :smile:
  • Gumiho
    Options
    Okay, using OnCustomRoomPropertiesChanged works fine !
    Thanks you ! :smiley:
  • Good to hear that it is working for you.

    Is it correct to update timers on each client using OnPhotonSerializeView with current time of master client as parameter ?


    Not really. You actually can use this somehow to create a timer but this is not recommended since it has two major disadvantages. The first is that OnPhotonSerializeView is called 20 times a second (default settings), so you would waste a lot of messages and bandwidth for unimportant information. Second is that this timer wouldn't be accurate due to latency.

    Of course there are (built-in) ways to solve at least the second occurring problem, but having a lot of unimportant messages is not the way to go.
  • Gumiho
    Options


    Not really. You actually can use this somehow to create a timer but this is not recommended since it has two major disadvantages. The first is that OnPhotonSerializeView is called 20 times a second (default settings), so you would waste a lot of messages and bandwidth for unimportant information. Second is that this timer wouldn't be accurate due to latency.

    Of course there are (built-in) ways to solve at least the second occurring problem, but having a lot of unimportant messages is not the way to go.

    Got it, thank you for this explanation ! :wink: