Why is PhotonNetwork.time giving me inconsistent results?

Options

Hello all,

When I create a room, I save PhotonNetwork.time in the room's customRoomProperties, like this:
void OnPhotonRandomJoinFailed()
    {
        Debug.LogError("Failed to join random room. Creating new room...");

        ExitGames.Client.Photon.Hashtable roomProps = new ExitGames.Client.Photon.Hashtable();
        roomProps.Add("t", PhotonNetwork.time);

        RoomOptions roomOps = new RoomOptions();
        roomOps.customRoomProperties = roomProps;

        PhotonNetwork.CreateRoom(null, roomOps, TypedLobby.Default);
    }
Once I create a room, I go ahead and instantiate the prefab on the network, like this:
public override void OnJoinedRoom()
    {
        GameObject myPaddle = PhotonNetwork.Instantiate("PlayerPaddle", Vector3.zero, Quaternion.identity, 0);
        myPaddle.AddComponent<PaddleController>();
    }
Then, in Unity's Start() method (for the newly instantiated prefab), I just compare the current PhotonNetwork.time to the one set when I created the room, like this:
void Start ()
    {
        object time;
        PhotonNetwork.room.customProperties.TryGetValue("t", out time);

        double gameTime = (double)time;
        Debug.Log("currentTime: " + PhotonNetwork.time + "  roomStartTime: " + gameTime);
    }
I end up getting an output along the lines of this:

currentTime: 2566900.73 roomStartTime: 2076135.993

As you can see, there is like a HUGE difference. Also to mention, when I stop and play again, currentTime will sometimes jump up to ~3million+; stopping and playing again, it will fall back down to ~2million+.

In the Photon tutorial pages on synchronization, I quote:
"Another good use case for Custom Properties is to store a room's "start time". When the game begins, store PhotonNetwork.time as property. That value is (approximately) the same for all clients in the room and with the start time, any client can calculate how long the game is running already and which turn it is."
How would a client calculate anything related to time with these issues?

--Thanks for the help.

Best Answer

Answers

  • Thanks vadim. Fixed it right up.