Search Unity

Allow Cmd and Rpc without a connection

Discussion in 'Multiplayer' started by Capn_Andy, Sep 30, 2015.

  1. Capn_Andy

    Capn_Andy

    Joined:
    Nov 20, 2013
    Posts:
    80
    I'd really like to use Cmd and Rpc functions, even without an active connection, to simplify single player & multiplayer code.

    Please? :3
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
  3. Capn_Andy

    Capn_Andy

    Joined:
    Nov 20, 2013
    Posts:
    80
    The way I'm currently doing things is similar to:

    Code (CSharp):
    1.     public void AssignNetworkAuthority() {
    2.         NetworkIdentity currentPlayer = Globals.playerTransform.GetComponent<NetworkIdentity>();
    3.         if (currentPlayer == null) {
    4.             //Debug.Log ("No player spawned yet, or playing locally.");
    5.         } else {
    6.             CmdAssignNetworkAuthority(currentPlayer.netId);
    7.         }
    8.     }
    9.  
    10.     [Command] protected void CmdAssignNetworkAuthority(NetworkInstanceId toId) {
    11.   // other stuff
    12.     }
    Basically, I have to build a "handler" function that decides first if the Cmd should be called. would be a lot easier if I could just collapse the logic into a single function though.