Search Unity

ServerRpc wont move the clients PlayerObject

Discussion in 'Netcode for GameObjects' started by KristenBoyGames, May 10, 2022.

  1. KristenBoyGames

    KristenBoyGames

    Joined:
    May 23, 2021
    Posts:
    38
    So the code goes like:
    Code (CSharp):
    1. UpdatePlayerStartPosServerRpc(new Vector3(25f, -0.2f, 23.78001f));
    and the ServerRpc goes like this
    Code (CSharp):
    1.  
    2.     [ServerRpc(RequireOwnership = false)]
    3.     public void UpdatePlayerStartPosServerRpc(Vector3 startpos)
    4.     {
    5.         NetworkManager.Singleton.LocalClient.PlayerObject.transform.position = startpos;
    6.  
    7.         LogClientRpc(startpos, NetworkManager.Singleton.LocalClientId.ToString());
    8.     }
    but the clients PlayerObject wont get moved.
     
  2. luke-unity

    luke-unity

    Joined:
    Sep 30, 2020
    Posts:
    306
    If you are calling this RPC already on the player object you just need to do `transform.position = startpos`. Right now your code always updates the code of the hosts player.
     
  3. KristenBoyGames

    KristenBoyGames

    Joined:
    May 23, 2021
    Posts:
    38
    i changed it to
    Code (CSharp):
    1.  [ServerRpc(RequireOwnership = false)]
    2.     public void UpdatePlayerStartPosServerRpc(Vector3 startpos)
    3.     {
    4.         gameObject.transform.position = startpos;
    5.  
    6.         LogClientRpc(startpos, NetworkManager.Singleton.LocalClientId.ToString());
    7.     }
    8.  
    and now it moves the host when called