Search Unity

Help Wanted [Mirror] Custom class not syncing on the first user's player instance on dedicated server.

Discussion in 'Multiplayer' started by wztk12, Jan 12, 2021.

  1. wztk12

    wztk12

    Joined:
    Feb 25, 2020
    Posts:
    18
    Hello guys,

    I'm trying to create a class which holds match details. Currently it looks like this:
    Code (CSharp):
    1. [Serializable]
    2. public class Match()
    3. {
    4.     public string id;
    5.     public List<uint> players = new List<uint>();
    6.     public bool isFull = false;
    7.     public bool inProgress = false;
    8.  
    9.     public Match(string id, GameObject player)
    10.     {
    11.         this.id = id;
    12.         players.Add(player.GetComponent<NetworkIdentity>().netId);
    13.     }
    14.     public Match(){ }
    15. }
    I've tested this class on a localhost instance with host and client and it works perfectly fine. However, when I put it on a dedicated server and run 2 client instances, it starts to become buggy. The players list is fine on the server and on both players in the second client, but the first client, which initializes this class, ends up with only second player netID inside players list. I've tried to save this data on a player instance and on a different object which is spawned on network alongside players, but the result is always the same and honestly I'm so stumped I don't even know how to debug this. I'd understand if it only had the initial value, but I have no clue why would it overwrite like this, especially since all other data sources, including first player copy on second client, are fine.

    I've tried multiple things: swapping list for a SyncList<uint> - that gave me weaver error, creating custom SyncList - same results as with List, swapping to an Array- same results as with List, Debug.Log to check if netID exists at the time of execution - it does, recreating a list every time a change is added (I've heard you have to do it in order to execute SetDirtyBit everywhere) - same results. This happens regardless of the data type - I've tried strings, signed ints and GameObjects. I've also checked if the version of data is correct on the dedicated server and it is.

    I'm using Unity 2019.3.6f1 and latest Mirror update.
    I've ran out of ideas, so I would appreciate any suggestions on how to resolve this.
    Thanks in advance.

    EDIT: I've resolved this now, I'm not sure what the issue was before, but I went back to an older version of script and added extra ClientRpc to ensure syncing and it works perfectly fine.
     
    Last edited: Jan 18, 2021
unityunity