Unity NetCode Clients can't send ServerRPC but host can

Viewed 41

Host can send ServerRPC but Clients cant. And Im sure that Clients are owner.

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");
    }
} 

Log as Host: "Hello World" "Key Pressed"

Log as a Client: "Key Pressed"

1 Answers

figured out it shouldnt destroy code on server side so I deleted OnNetworkSpawn() and added if(!IsOwner) return; on Update() method

Related