Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

ClientRpc not working OnStartLocalPlayer

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

  1. wahyuway

    wahyuway

    Joined:
    Oct 7, 2013
    Posts:
    84
    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:
    220
    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!