I have setup a SyncListStruct class and using it in class deriving from NetworkBehaviour. When i add new items to it when both client and server are connected it syncs well.
But when i disconnect client and reconnect the list is empty. How can i make it so client can get it synced when he connects.
[System.Serializable]
public struct ItemClass
{
public string name;
public int amount;
public int maxAmount;
public ItemClass(string name, int amount)
{
this.name = name;
this.amount = amount;
this.maxAmount = 5;
}
}
`
public class SyncListItem : SyncListStruct<ItemClass>
{
}
public class NetworkedInventoryClass : NetworkBehaviour
{
public SyncListItem inventory = new SyncListItem();
}
public class test : NetworkBehaviour // class on player
{
public NetworkedInventoryClass inventory;
[Command]
public void CmdAddItem(string itemName, int itemAmount, int position)
{
inventory.inventory.Add(new ItemClass(itemName, itemAmount));
}
}
`