Search Unity

Help Wanted Mirror Networking: SyncVar won’t sync from server to client

Discussion in 'Multiplayer' started by plokkum, Jan 8, 2021.

  1. plokkum


    May 28, 2013
    I have a pretty basic question I can't seem to figure out.

    I have two SyncVars (without a hook) on my client gameObject that holds a string for the currently loaded level and the state of it. I invoke a [Command] on this client when the level is loaded:
    Code (CSharp):
    1. [Command]
    2.     public void CmdFinishedLoadingLevel(bool isFinished, string levelPath)
    3.     {
    4.         currentLoadedLevel = levelPath;
    5.         finishedLoadingLevel = isFinished;
    6.     }
    This command is executed on the server and the variables are changed.
    However, the variables currentLoadedLevel and finishedLoadingLevel on my client gameObject are not being synced over. Neither would it trigger a hook if I were to add one.

    Code (csharp):
    1. public class GamePlayer : NetworkBehaviour
    2. {
    3.     [SyncVar]
    4.     private bool finishedLoadingLevel;
    5.     public bool FinishedLoadingLevel => finishedLoadingLevel;
    7.     [SyncVar]
    8.     private string currentLoadedLevel;
    9.     public string LoadedLevel => currentLoadedLevel;
    10. }
    Any ideas as to why these SyncVars are not being synced back to the client? I'm sure it has been asked thousands of times...
  2. plokkum


    May 28, 2013
    Well I found out my client's connections weren't in a Ready state after switching scenes. Manually setting them to ready after scene change is completed makes them receive the updates again. Just thought I'd share in case anyone else encounters the same 'issue'.