Search Unity

Why cant I change the name on the client?

Discussion in 'Multiplayer' started by RChrispy, Apr 23, 2016.

  1. RChrispy

    RChrispy

    Joined:
    Dec 18, 2013
    Posts:
    71
    Code (CSharp):
    1.     public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
    2.     {
    3.         //base.OnServerAddPlayer(conn, playerControllerId);
    4.         for (int i = 0; i < SpawnPoints.Count; i++)
    5.         {
    6.             if (SpawnPoints[i].Occupied == false)
    7.             {
    8.                 //init
    9.                 //base.OnServerAddPlayer(conn, playerControllerId);
    10.                 GameObject player = (GameObject)Instantiate(playerPrefab, SpawnPoints[i].Point.position, SpawnPoints[i].Point.rotation);
    11.                 player.name = "Player_" + i;
    12.  
    13.                 //playerTracker.Add(player);
    14.                 SpawnPoints[i].PlayerGO = player;
    15.                 SpawnPoints[i].uID = i;
    16.                 SpawnPoints[i].Occupied = true;
    17.  
    18.                 //set on player
    19.                 aPlayer tPlayer = PathAddPlayer(new aPlayer("Player_" + i.ToString(), i, i, 1));
    20.                 player.GetComponent<CarControl>().MyPlayer = PlayerList[i];
    21.  
    22.                 NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
    23.                 //NetworkServer.SendToClientOfPlayer(player, MsgType.UpdateVars, null);
    24.                 //player.GetComponent<CarControl>().RpcCallFromServerOnClient(player, tPlayer, SpawnPoints);
    25.                 return;
    26.             }
    27.         }
    28.     }
    The Values are set perfektly on Server side but on client there are no values even the name of the PlayerGameObject ist (Clone)

    Anyone knows how to sync this on spawn?
     
  2. srylain

    srylain

    Joined:
    Sep 5, 2013
    Posts:
    159
    Make sure that the values you want to have synced are SyncVars.
     
  3. Oshroth

    Oshroth

    Joined:
    Apr 28, 2014
    Posts:
    99
    GameObject.name is not a network-synced value. You will need to set it client-side in a OnStartLocalPlayer(). Unity uses NetworkIdentity.netid to identify Network objects across the network
     
  4. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    460
    Why not create a Player or PlayerSettings class, which holds the player's name instead of using the hierarchy system.