Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

UI not syncing over clients

Discussion in 'Multiplayer' started by FuzzyBalls, Sep 28, 2015.

  1. FuzzyBalls

    FuzzyBalls

    Joined:
    Jun 12, 2014
    Posts:
    47
    Hi,

    Having some troubles with syncing UI over all clients.

    So I have a game with multiple players, each players has UI assigned to them. When they die, I update the UI (lives etc) but the UI only updates on the host, the clients UI doesn't update.

    My canvas has a network identity component with local player authority checked.

    The code i'm using to update UI:

    Code (CSharp):
    1.  
    2.     [Command]
    3.     public void CmdOnDeath ()
    4.     {
    5.         lives = lives - 1;
    6.  
    7.         var pgo = GameObject.Find ("Player" + (playerNumber + 1) + "_UI").transform.GetChild (0).gameObject;
    8.         pgo.transform.FindChild ("heart" + (lives + 1)).gameObject.SetActive (false);
    9.  
    10.         RpcRespawn ();
    11.     }
    any ideas of what i'm doing wrong?
     
  2. FuzzyBalls

    FuzzyBalls

    Joined:
    Jun 12, 2014
    Posts:
    47
  3. Noob4Sale

    Noob4Sale

    Joined:
    Mar 10, 2015
    Posts:
    11
    Isn't a ClientRPC needed to send the info from the host to other objects?
     
  4. FuzzyBalls

    FuzzyBalls

    Joined:
    Jun 12, 2014
    Posts:
    47
    Changing it to ClientRPC doesn't seem to fix my issue, just makes it worse.
     
  5. FuzzyBalls

    FuzzyBalls

    Joined:
    Jun 12, 2014
    Posts:
    47
  6. Capn_Andy

    Capn_Andy

    Joined:
    Nov 20, 2013
    Posts:
    80
    Noob4Sale was correct, you're thinking about your multiplayer code wrong. "Commands" are called BY player objects and run ON the server (so you are getting the results you expect); "RPC" calls are called BY the server and run ON clients (which sounds closer to what you want, but then the host wouldn't see the ui updates either).

    You could do a combination, where first the Command executes on the server and then RPC calls are made to each client to keep them in sync;

    or you could locally update each client before the command is sent;

    or you could use SyncVars and add a networkID to each of the UIs;

    there's a bunch of ways to accomplish what you're trying to do, but the way you are doing it now is giving unsurprising results. :)
     
  7. stoilcho

    stoilcho

    Joined:
    Sep 8, 2014
    Posts:
    30
    Sorry to whine on your random thread but i need to vent. why the hell is so much hoop jumping needed to accomplish this. It's called a high level api but it's it's frustrating to use and poorly documented. why can't i just have object be in sync across the network period with sync var and all that stupid bul. 80% of networked game will need a shared ui
     
  8. srylain

    srylain

    Joined:
    Sep 5, 2013
    Posts:
    159
    It's not Unity's fault you don't understand how it works. Unity can only do so much, and the user has to fill in the rest of it. Especially for something you can use for free and make money off of. But unless you didn't know, you can use SyncVars to just automatically keep values updated across clients, and to keep server authority SyncVars can only be changed on the server in order for them to be properly propagated across the clients.
     
  9. stoilcho

    stoilcho

    Joined:
    Sep 8, 2014
    Posts:
    30
    I like Unity a lot but IMO the workflow often tends to be unintuitive. Thanks for the reply anyway - I'll give SyncVar a shot.