OnPhotonSerializeView Hashtable?

Options
Hi all,

I've been struggling to get my Hashtable to sync in my project. Please can someone advise? All of my other variables sync perfectly, except the Hashtable:



using System.Collections;
using System.Linq;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Hashtable = ExitGames.Client.Photon.Hashtable;


[RequireComponent(typeof(PhotonView))]
public class Manager_Host : Photon.MonoBehaviour, IPunObservable {

bool host = false;
public Manager_Game manager_Game;
public Manager_UI manager_UI;

// --------------------------------------------------------------------------------
// -------------------------------- Game Variables --------------------------------
// --------------------------------------------------------------------------------
public Hashtable cachedPlayerList = new ExitGames.Client.Photon.Hashtable();

public bool gamePaused = false;
public int totalPhaseTicks;
public bool TRIGGERED_lobby_creating_roles = false;
public bool TRIGGERED_lobby_starting_game = false;
public bool TRIGGERED_night_waiting_for_moves = false;
public int currentTimer = 0;
public string currentPhase;

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
if (stream.isWriting) {
if (host) {
stream.SendNext(cachedPlayerList);

stream.SendNext(gamePaused);
stream.SendNext(totalPhaseTicks);
stream.SendNext(TRIGGERED_lobby_creating_roles);
stream.SendNext(TRIGGERED_lobby_starting_game);
stream.SendNext(TRIGGERED_night_waiting_for_moves);
stream.SendNext(currentTimer);
stream.SendNext(currentPhase);
}
} else {
cachedPlayerList = (Hashtable)stream.ReceiveNext();

gamePaused = (bool)stream.ReceiveNext();
totalPhaseTicks = (int)stream.ReceiveNext();
TRIGGERED_lobby_creating_roles = (bool)stream.ReceiveNext();
TRIGGERED_lobby_starting_game = (bool)stream.ReceiveNext();
TRIGGERED_night_waiting_for_moves = (bool)stream.ReceiveNext();
currentTimer = (int)stream.ReceiveNext();
currentPhase = (string)stream.ReceiveNext();
}


}

}





Comments

  • Hi @marshall,

    if those values doesn't need to be updated very often (multiple times per second) you can also store them in the Custom Room Properties and make them accessible for each client that way. I guess there is no problem with all of the above named bool and string values.

    Besides that the totalPhaseTicks and currentTimer values should not be synchronized the way you want to do it. The better option here might be (example for the timer) to store the start time and let each client calculate the timer on their own. Therefore you can store the PhotonNetwork.ServerTimestamp when you start the game. All clients will receive this value and can calculate the timer by calculating the difference between the current time and the stored time.