Search Unity

Sync isActive to other Clients

Discussion in 'Multiplayer' started by iossif, Jun 2, 2016.

  1. iossif

    iossif

    Joined:
    Mar 4, 2011
    Posts:
    332
    what i want to do:

    when client A presses a button, i want a child of the player character to become active for a short time.

    what works so far:

    when i press the button, i see the object become active on the client that presses the button and on the server.

    i do it this way:

    Code (CSharp):
    1.  
    2.         //in Update
    3.         if (Input.GetKeyDown(KeyCode.Space))
    4.         {
    5.             StartCoroutine(Slash());
    6.         }
    7. .
    8.  
    9.     IEnumerator Slash()
    10.     {
    11.         slashObject.SetActive(true);
    12.         CmdSlashOn();
    13.         yield return new WaitForSeconds(0.3F);
    14.         slashObject.SetActive(false);
    15.         CmdSlashOff();
    16.     }
    17. .
    18.  
    19.     [Command]
    20.     void CmdSlashOn()
    21.     {
    22.         slashObject.SetActive(true);
    23.     }
    24.  
    25.     [Command]
    26.     void CmdSlashOff()
    27.     {
    28.         slashObject.SetActive(false);
    29.     }
    30.  
    what i want and cannot figure out how to do:

    if there are two clients connected to the server, i just see the object becoming active on the client that presses the button and on the server. the other client is NOT seing the object become active. how can i send the information about the isActive change to all other clients?

    thanks for your help!
     
  2. fleap3

    fleap3

    Joined:
    Dec 7, 2013
    Posts:
    5
    I'm having the same problem. So, bump? Is that how it works?
     
  3. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    You have to call RPC function in the Command function.

    Command : client -> server
    RPC : server -> all clients
     
  4. fleap3

    fleap3

    Joined:
    Dec 7, 2013
    Posts:
    5
    What if the object I want to disable has local player authority so when the Server tries to disable it for other clients it can't because it doesn't have authority?
     
  5. srylain

    srylain

    Joined:
    Sep 5, 2013
    Posts:
    159
    Server has authority over everything, as that's part of UNET. A client should only ever have access to its own player, while the server controls everything.

    So pretty much, in both of your Commands you need to call an RPC that will basically tell the clients what to do. As is, you're only telling the server and not the other clients that you activated.