Clients can't send ServerRPC but host can

Host can send ServerRPC but Clients cant

using Unity.Netcode;
using UnityEngine;

public class NetwrokRpcTest : NetworkBehaviour
{
    public override void OnNetworkSpawn()
    {
        if(!IsOwner) Destroy(this);
    }

    void Update()
    {
        if(Input.GetKeyDown(KeyCode.M)){
            testServerRpc();
            Debug.Log("Key pressed");
        }       
    }

    [ServerRpc]
    void testServerRpc(){
        Debug.Log("Hello world");
    }
}

as Host:
8402289--1109436--host.PNG

as a Client:
8402289--1109442--client.PNG

8402289--1109436--host.PNG
8402289--1109442--client.PNG

Not sure of the issue here - your Host (ie, client + server) is receiving the ServerRpc and your client is not. What does your server log show?

if(!IsOwner) Destroy(this);
code destorys itself if its not owner so there is no log in server side

I just realized while writing the reply… its destroy code on server side. deleted onspawn method and added
if(!IsOwner) return; in Update. I should use Rubber duck debbuging next time.
8676540--1169463--upload_2022-12-20_18-15-38.png

1 Like