Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Unity Multiplayer ClientRpc not working OnStartLocalPlayer

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

  1. wahyuway

    wahyuway

    Joined:
    Oct 7, 2013
    Posts:
    81
    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:
    212
    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!
     
unityunity