Search Unity

Network Manager playerControllerId always = 0

Discussion in 'Multiplayer' started by smitchell, Sep 20, 2015.

  1. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    Hey,

    I'm fairly new to multiplayer stuff, so maybe i'm just being dumb. But for some reason when I override OnServerAddPlayer () and log 'playerControllerId' it always returns 0.

    Any ideas why?

    Code (CSharp):
    1.     public override void OnServerAddPlayer (NetworkConnection conn, short playerControllerId)
    2.     {
    3.         Debug.Log ("playerControllerId = " + playerControllerId);
    4.  
    5.         var spawnPosition = PlayerSpawner.instance.GetSpawnPositionForPlayer (playerControllerId);
    6.         var player = (GameObject)Instantiate (base.playerPrefab, spawnPosition, Quaternion.identity);
    7.  
    8.         NetworkServer.AddPlayerForConnection (conn, player, playerControllerId);
    9.     }
     
  2. _Adriaan

    _Adriaan

    Joined:
    Nov 12, 2009
    Posts:
    481
    You may see a 'player' as a client + controller, so what's happening is that your controllers are always the first and only created controllers on those clients :)

    There is a bit of a description here.

    EDIT: So just to clarify, this playerControllerId enables you to have multiple players on a client. For example, 1 computer (client) with 2 gamepads (controllers).
     
    Last edited: Sep 21, 2015