NullReferenceException: Object reference not set to an instance of an object
Unity.Netcode.NetworkBehaviour.get_NetworkManager () (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.4/Runtime/Core/NetworkBehaviour.cs:219)
rpc.MessageServerRpc () (at Assets/rpc.cs:40)
rpc.Update () (at Assets/rpc.cs:21)
here is my code:
[SerializeField] float Countdown = 3f;
//Update is called once per frame
void Update()
{
Countdown -= Time.deltaTime;
if (Countdown <= 0)
{
if (!NetworkManager.Singleton.IsHost)
{
Debug.Log("Lets tell the server to message");
MessageServerRpc();
}
else
MessageClientRpc();
Countdown = 4f;
}
}
[ServerRpc(RequireOwnership = false)] //also tried without the requireownership
private void MessageServerRpc()
{
Debug.Log("Ive Got This Running In My Server");
}
i think i just dont know how to run Rpc calls. for some reason, both the server and the clients are calling this method and executing. (when only the server should execute)
why is this happening?