Hey,
I’m struggeling with the SyncList for some hours now.
What I am trying to accomplish: Load player items into a SyncList inside the OnServerAddPlayer before AddPlayerForConnection.
Issue: I’m getting this error on the server side
Here is the code of the uploaded minimal project.
public class MyNetworkManager : NetworkManager {
public GameObject StartItemPrefab;
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId) {
GameObject player = (GameObject)Instantiate(this.playerPrefab, startPositions[0].transform.position, Quaternion.identity);
// Load item
GameObject item = Instantiate(StartItemPrefab);
NetworkServer.Spawn(item);
player.GetComponent<Player>().items = new SyncListUInt();
// Give player the item
player.GetComponent<Player>().items.Add(item.GetComponent<NetworkIdentity>().netId.Value);
NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
}
}
public class Player : NetworkBehaviour {
public SyncListUInt items = new SyncListUInt();
public override void OnStartClient() {
Debug.Log("Item " + items[0]);
}
}
Thanks in advance for any help!
3045834–228333–SyncListError.rar (3.28 MB)