Search Unity

ServerRPC not reacting to call

Discussion in 'Netcode for GameObjects' started by Lokefs3000, Nov 12, 2021.

  1. Lokefs3000

    Lokefs3000

    Joined:
    May 20, 2021
    Posts:
    2
    I have recently been trying to learn and make a multiplayer game. but during so i encountered a problem. the problem being that my client cant call my ServerRPC. and i have no idea why, i have tried everything i can think of.

    Code (CSharp):
    1. using Unity.Netcode;
    2. using UnityEngine;
    3.  
    4. namespace Game
    5. {
    6.     public class Player : NetworkBehaviour
    7.     {
    8.         public float Speed;
    9.  
    10.         public NetworkVariable<Vector3> Position = new NetworkVariable<Vector3>();
    11.  
    12.         public override void OnNetworkSpawn()
    13.         {
    14.             if (IsOwner)
    15.             {
    16.                 Move();
    17.             }
    18.         }
    19.  
    20.         [ServerRpc]
    21.         public void SubmitPositionRequestServerRpc(ServerRpcParams rpcParams = default)
    22.         {
    23.             Position.Value = this.transform.position;
    24.         }
    25.  
    26.         public void Move()
    27.         {
    28.             if (NetworkManager.Singleton.IsServer)
    29.             {
    30.                 Position.Value = Position.Value = this.transform.position;
    31.             }
    32.             else
    33.             {
    34.                 SubmitPositionRequestServerRpc();
    35.             }
    36.         }
    37.     }
    38. }