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.