Hello. I am updating a network list from the server, and immediately calling a client RPC to spawn game objects using data from that List. However, the list does not appear to be updating on client devices. Reading the list right before calling the client RPC shows that it has been properly written by the host, but reading it on the client device during the client RPC call shows that it is not identical to the host’s list. Can anyone explain why this might be the case? I thought that network lists were constant between the host and all clients. I thought maybe the problem was the server needed time to sync the list to clients, but implementing a coroutine that waited a few seconds between updating the list and calling the client RPC did not work.
The code for updating the list and calling the client rpc is given below.
//Is host
Debug.Log("Old List");
DebugList();
//Update the list
Ship[] ships = FindObjectsOfType<Ship>();
foreach (Ship ship in ships)
{
//find ship in list
int i = 0;
foreach (ShipData shipData in WargameManager.Instance.ShipList)
{
if (ship.TeamIndex == shipData.TeamIndex && ship.ShipID == shipData.ShipId)
{
Debug.Log("Ship Updated");
//Ship Found - create new data and update list
WargameManager.ShipData newShipData = new ShipData(ship.TeamIndex, ship.ShipID, ship.EMCONRange, ship.ActiveRange, true, ship.IsActive, ship.CurrentHexTile.HexGridIndex[0], ship.CurrentHexTile.HexGridIndex[1]);
WargameManager.Instance.ShipList.RemoveAt(i);
WargameManager.Instance.ShipList.Add(newShipData);
break;
}
i++;
}
}
Debug.Log("New Ship List");
DebugShipList();
PlayerNetwork.ReturnLocalPlayer().UpdateShipListClientRpc();
And here is the client RPC
[ClientRpc]
public void UpdateShipListClientRpc()
{
//Only run on clients (not host)
if (PlayerNetwork.ReturnLocalPlayer().Client)
{
Debug.Log("Running Client RPC");
WargameManager.Instance.DebugShipList();
//Destory all Ships
Ship[] ships = FindObjectsOfType<Ship>();
foreach (Ship _ship in ships)
{
_ship.CurrentHexTile.RemoveShip(_ship);
Destroy(_ship.gameObject);
Debug.Log("Ship Destroyed");
}
//Spawn new ones from list
}
}