I’m having a lot of trouble with SyncLists. I have a script on my player prefab that is being spawned by the default NetworkManager with localPlayerAuthority that needs to have a list of ints that are synced between clients.
Currently when I start a host and then connect as a client, the two player’s SyncList’s will be properly initialized on the client but on the server only the host’s SyncList is initialized.
When I run the below code the console on the server reads:
*NetID 3’s sync list on editor contains 5 things
NetID 4’s sync list on editor contains 0 things*
While on the client it reads:
*NetID 3’s sync list on standalone contains 5 things
SyncList not initialized
SyncList not initialized
SyncList not initialized
SyncList not initialized
SyncList not initialized
NetID 4’s sync list on standalone contains 5 things*
Here is my code:
public class PlayingField : NetworkBehaviour
{
public SyncListInt monsterSyncList = new SyncListInt();
public GameObject tempMonsterCard;
void Awake()
{
monsterSyncList.Callback = OnMonsterChanged;
}
void Start()
{
if (hasAuthority)
{
Debug.Log("Is local player");
for (int i = 0; i < 5; i++)
{
monsterSyncList.Add(-1);
}
}
Debug.LogError("NetID " + netId + "'s sync list on " + (Application.isEditor ? "editor " : "standalone ") + "contains " + monsterSyncList.Count + " things");
}
public bool setMonsterCardByIndex(GameObject card, int i)
{
if (hasAuthority)
{
monsterSyncList *= card.GetComponent<ICard>().cardID;*
return true;
}
return false;
}
private void OnMonsterChanged(SyncListInt.Operation op, int index)
{
if (SyncListInt.Operation.OP_SET == op && !hasAuthority)
{
if (monsterSyncList[index] != -1)
{
Debug.Log(“Synced”);
}
}
}
}
Any help would be appreciated. I’ve been working at this for hours with no end in sight.