1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. Unity 5.6 is now released.
    Dismiss Notice
  3. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  4. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  5. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    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:
    66
    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:
    151
    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!