Serverrpc calls not working on client

Hi! So I am doing a multiplayergame for college but i am having trouble with ServerRpc calls. When i call the method OnHide, the rpc call seems to not be working. I am using Unity InputSystem and relay.

 public override void OnNetworkSpawn()
  {
      base.OnNetworkSpawn();
      SetPlayer();

  }


  // Update is called once per frame
  void FixedUpdate()
  {
      if (!IsOwner) return;
      if (_moving)
          MovePlayer(); //client transform
  }

  void SetPlayer()
  {
      PlayerInput playerInput = GameObject.Find("@PlayerInput").GetComponent<PlayerInput>();

      _actionMap = playerInput.actions.FindActionMap("PlayerInGame");


      playerInput.actionEvents[0].AddListener(this.OnMovement);
      playerInput.actionEvents[1].AddListener(this.OnHide);
      playerInput.actionEvents[2].AddListener(this.OnAttack);

      _actionMap.FindAction("Hide").Disable(); 
  }

 public void OnHide(InputAction.CallbackContext context) //it calls when i use a rightclick
 {
     Debug.Log("HIDING VALUE "+ _hiding.Value);
     if (!IsOwner || _hiding.Value) return;
     Debug.Log("Distanciaa " + Vector3.Distance(transform.position, pBehaviour.transform.position));
     if (Vector3.Distance(transform.position, pBehaviour.transform.position) < 3f)
     {
         
         OnHideServerRpc();
     }
 }

 [ServerRpc]
 private void OnHideServerRpc()
 {
     
     _hiding.Value = true;
     SwapInputAction();
     ChangeSpriteClientRpc(pBehaviour.spriteNumber, pBehaviour.NetworkObjectId);
     StartCoroutine(HideCoroutine(10)); 

 }

 [ClientRpc]
 private void ChangeSpriteClientRpc(int spriteNumber, ulong NID)
 {
     Debug.Log("sprite change");
     GetComponent<SpriteRenderer>().sprite = allSprites[spriteNumber]; /
     var hideGO = NetworkManager.Singleton.SpawnManager.SpawnedObjects[NID].gameObject;
     hideGO.gameObject.SetActive(!hideGO.gameObject.activeSelf);

 }
 private IEnumerator HideCoroutine(int time)
 {
     yield return new WaitForSeconds(time);
     _hiding.Value = false;
     ChangeSpriteClientRpc(0, pBehaviour.NetworkObjectId);
     pBehaviour = null;
    
 }

for the host it’s working fine which i expect because it recieves the call like they are normal methods, but the thing is that the clients don’t make neither call. With the movement I had the same problem but i ended up doing it client authoritative and now it’s moving perfectly.

Every objetct inherits network behaviour. I am using networkmanager prefab for the player

The object pBehaviour is not instantiated. it is from the scene.

Don’t accept a “seem”, confirm it. You could add a Debug.Log or set a breakpoint. You have some but maybe not enough to see where the execution path takes a different route.

It depends on the ownership of the object. I assume the host owns that object, so it works for the host and it should go on and send that information to every client.

But if you right-click on the client, the same object will be host-owned and thus the client (non-owner) will not make the call.

Note that ServerRpc/ClientRpc are outdated. These days we use just [Rpc] with parameters eg to control who receives the call.

hi! Sorry, you are right. The movement code is working fine because i have a debug and which is gettin done, but the OnHide method don’t do the clientrpc debug when i use the client, but yes when i use the host, that’s why I assumed that the rpc call wasn’t being made.

The use of IsOwner it’s because we want it to be server authoritative. In the unity editor the client object is marked as owner and I cannot take the if (!IsOwner || _hiding.Value) return because then it doesn’t find the playerInputs

I have a debug showing the hiding value and it shows true and false at the same time :cry:, i don’t know why is that happening

Because you have two instances of the object? One for host and one for client I assume.

yes but it only happens in the client, the host only shows its debug, is this okay?

It does indeed do the rpc call, but there are no changes in the client

Hi! So everything was working but the problem was this line because I was asking the server to acces something that he has no idea it’s there.
ChangeSpriteClientRpc(pBehaviour.spriteNumber, pBehaviour.NetworkObjectId);
Instead I did this:

 public void OnHide(InputAction.CallbackContext context) 
 {
   
     if (!IsOwner) return;
     Debug.Log(GetComponent<SpriteRenderer>().sprite);
     Debug.Log("Distanciaa " + Vector3.Distance(transform.position, pBehaviour.transform.position));
     if (Vector3.Distance(transform.position, pBehaviour.transform.position) < 3f)
     {
         
         OnHideRpc(pBehaviour.spriteNumber, pBehaviour.NetworkObjectId);
         pBehaviour = null;
     }
 }

 [Rpc(SendTo.Server)]
 private void OnHideRpc(int spriteN, ulong NID)
 {
     
     ChangeSpriteRpc(spriteN, NID);
     StartCoroutine(HideCoroutine(10, NID)); 

 }

And now everything is working perfectly. A rookie mistake that costed me 3 days to notice!