ServerRpc method doesn't work on Client

Hello! I’ve been trying to solve this issues for couple days but haven’t had success so far.
I have a script, it is attached to the Player prefab. The Player prefab, in its turn, has a Network Object component and is set as the Player prefab in Network manager.

When I start as a host (NetworkManager.Singleton.StartHost():wink: everything works, but if I connect as a client (NetworkManager.Singleton.StartCleint():wink: the ServerRpc method doesn’t work on Client.

Please find the script below:

using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;

public class TestingServerRpc : NetworkBehaviour
{
    void Update()
    {
       if (!IsOwner)
            return;
        if (Input.GetMouseButtonDown(0))
        {
            DoStuffServerRpc();
        }

    }

    [ServerRpc(RequireOwnership = false)]
    public void DoStuffServerRpc()
    {
        Debug.Log("It works!");
    }
}

Thank you!

ServerRpc method only work in Server. If you want to send Rpc function from a Client you must use ServerRpc and ClientRpc both.

[ServerRpc(RequireOwnership = false)]
private void DoSomethingServerRpc()
{
DoSomethingClientRpc();
}

[ClientRpc]
private void DoSomethingClientRpc()
{
print(“Printed on all Clients”);
}
1 Like

@

Thank you very much, that helped a lot!