Search Unity

  1. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  2. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  3. Unity 2017.1 is now released.
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  6. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

Unity Multiplayer ClientRpc not working OnStartLocalPlayer

Discussion in 'Multiplayer Networking' started by wahyuway, Mar 19, 2017.

  1. wahyuway

    wahyuway

    Joined:
    Oct 7, 2013
    Posts:
    72
    Hi, i tried to instantiate my player object using ClientScene.AddPlayer and make necessary change in OnServerAddPlayer.

    The problem is when i need to send my player parameter to other client using [Command] and [ClientRpc], ClientRpc did not executed.
    This some snippet of my player networkbehavior
    Code (CSharp):
    1.     public override void OnStartLocalPlayer() {
    2.         if (hasAuthority)
    3.             CmdCreateChar();
    4.     }
    5.  
    6.     [Command]
    7.     void CmdCreateChar()
    8.     {
    9.         print("client command me to execute this");
    10.         RpcCreateChar();
    11.     }
    12.  
    13.     [ClientRpc] //never called
    14.     void RpcCreateChar()
    15.     {
    16.         print("Server send this rpc to execute on all client");
    17.     }
    Any hint whats wrong?
     
    Last edited: Mar 19, 2017
  2. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    199
    Hmm, have you tried using the OnStartClient override instead of OnStartLocalPlayer? The documentation isn't very clear here but based on the naming of the OnStart* methods of a NetworkBehaviour script, I would assume that OnStartLocalPlayer is used in more unique scenarios, where as OnStartClient will be called when the object is network-ready in the client.

    Not sure if this will help but hopefully it does!