Host executes "Rpc NotMe" twice with each call (1.8.0)
Description
When a client, that is not the host, executes an Rpc with target set to NotMe, the host will execute the Rpc twice, locally.
Reproduce Steps
- Create an empty scene with a network manager and transport.
- Create a script that inherits from NetworkBehaviour and add it to an empty object in the scene.
- Add an rpc function with the target set to [Rpc(SendTo.NotMe)] and add Debug.Log("Not Me RPC Executed"); to the function.
- Run a host and a client version. (I am using ParrelSync to connect as a client)
- Execute the function from a client
- Host will debug the message to the console twice with each call.
Actual Outcome
When I was executing rpcs with clients, the host executed the rpcs twice, while clients only executed it once. The host should only execute it once as well. This only happens on the host, when a regular client executes the rpc. So this problem does not occur on regular clients.
Expected Outcome
The rpc should only execute once with each call, just like clients.
Screenshots
Host console when rpc was executed from a client: (Bug)
Client console when rpc was executed from the host: (Correct)
Environment
- OS: Windows 10 Pro 22H2 Build 19045.3930
- Unity Version: 2022.3.19f1
- Netcode Version: 1.8.0
Additional Context
The same problem occured when I was using Unity version 2022.3.10f1 and Netcode 1.8.0 (manual upgrade)
What is happening is that when sending the RPC - NotMeRpcTarget.cs code in question:
m_GroupSendTarget.Target.Send(behaviour, ref message, delivery, rpcParams);
if (!behaviour.IsServer)
{
m_ServerRpcTarget.Send(behaviour, ref message, delivery, rpcParams);
}
It will gather the client side of the host and send the RPC but then also send it to the server (which is also the host). Because the host acts as both client and server it will receive two messages.
This could be solved by changing the code to:
m_GroupSendTarget.Target.Send(behaviour, ref message, delivery, rpcParams);
if (!behaviour.IsServer && !m_NetworkManager.ServerIsHost)
{
m_ServerRpcTarget.Send(behaviour, ref message, delivery, rpcParams);
}
Fix is in this PR: https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/pull/2834 Will land in an upcoming release