-
Notifications
You must be signed in to change notification settings - Fork 457
Description
Description
When calling a [ClientRpc] method from within the ConnectionApprovalCallback in a GameManager class, a ConnectionRequestMessage is unexpectedly received on the client side, resulting in an error. According to the error message, this should not occur, and it requests reporting to the Netcode for GameObjects team. The RPC fails to execute on the clients, disrupting the intended synchronization of the game model.
Reproduce Steps
Set up a Unity project with Netcode for GameObjects installed.
Create a GameManager class inheriting from NetworkBehaviourSingleton (or similar singleton pattern).
In the Start method, initialize a GameModel and assign the ConnectionApprovalCallback to a method named HandleConnectionRequest.
In HandleConnectionRequest, approve the connection, process the request payload, and call a [ClientRpc] method (UpdateModelClientRpc) with serialized game model data.
Enable Multiplayer Play Mode in Unity to open multiple editor instances.
Start one instance as a host (e.g., NetworkManager.StartHost()) and another as a client (e.g., NetworkManager.StartClient()).
Observe the error in the client’s console upon connection attempt.
Actual Outcome
The client logs the following error:
[Netcode] A ConnectionRequestMessage was received from the server on the client side. NetworkTransport: Unity.Netcode.Transports.UTP.UnityTransport UnityTransportProtocol: UnityTransport. This should not happen. Please report this to the Netcode for GameObjects team at https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues and include the following data: Message Size: 214. Message Content: 02 02 7d 9a e2 a5 21 b2 36 17 b3 11 46 c4 ca 04 01 2a b2 f1 50 01 e9 3a b6 d2 01 39 3b e8 2c 01 ab c9 50 60 01 53 a3 38 44 11 d3 f6 1c b8 01 7f 10 0d af 01 f3 a2 4a 4a 01 a6 22 89 97 01 e9 4e 31 0d 01 b5 fe 01 74 11 be 97 be 73 01 bd 23 d8 d0 01 58 aa fb 1c 01 9d 9a 5c 01 01 e9 51 97 17 01 8a f7 e7 83 01 ee 80 1f c6 01 42 7f 88 c6 01 97 a3 f5 46 01 c2 40 2e a3 01 4e 67 03 d2 01 00 00 00 00 01 00 00 00 00 01 00 00 00 00 01 00 00 00 00 01 00 00 00 00 01 00 00 00 00 01 00 00 00 00 01 7c 12 88 12 c2 66 9b 2a 28 00 00 00 7b 22 41 76 61 74 61 72 49 6e 64 65 78 22 3a 30 2c 22 4e 69 63 6b 6e 61 6d 65 22 3a 22 50 6c 61 79 65 72 33 38 34 22 7d
UnityEngine.Debug:LogError (object)
Unity.Netcode.NetworkLog:LogError (string) (at ./Library/PackageCache/com.unity.netcode.gameobjects@c694fb5041d4/Runtime/Logging/NetworkLog.cs:34)
Unity.Netcode.NetworkManagerHooks:OnVerifyCanReceive (ulong,System.Type,Unity.Netcode.FastBufferReader,Unity.Netcode.NetworkContext&) (at ./Library/PackageCache/com.unity.netcode.gameobjects@c694fb5041d4/Runtime/Messaging/NetworkManagerHooks.cs:95)
Unity.Netcode.NetworkMessageManager:CanReceive (ulong,System.Type,Unity.Netcode.FastBufferReader,Unity.Netcode.NetworkContext&) (at ./Library/PackageCache/com.unity.netcode.gameobjects@c694fb5041d4/Runtime/Messaging/NetworkMessageManager.cs:315)
Unity.Netcode.NetworkMessageManager:HandleMessage (Unity.Netcode.NetworkMessageHeader&,Unity.Netcode.FastBufferReader,ulong,single,int) (at ./Library/PackageCache/com.unity.netcode.gameobjects@c694fb5041d4/Runtime/Messaging/NetworkMessageManager.cs:397)
Unity.Netcode.NetworkMessageManager:ProcessIncomingMessageQueue () (at ./Library/PackageCache/com.unity.netcode.gameobjects@c694fb5041d4/Runtime/Messaging/NetworkMessageManager.cs:448)
Unity.Netcode.NetworkManager:NetworkUpdate (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@c694fb5041d4/Runtime/Core/NetworkManager.cs:340)
Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@c694fb5041d4/Runtime/Core/NetworkUpdateLoop.cs:191)
Unity.Netcode.NetworkUpdateLoop/NetworkEarlyUpdate/<>c:<CreateLoopSystem>b__0_0 () (at ./Library/PackageCache/com.unity.netcode.gameobjects@c694fb5041d4/Runtime/Core/NetworkUpdateLoop.cs:214)
Additionally, the [ClientRpc] method (UpdateModelClientRpc) does not execute on the clients, and the game model is not updated as intended.
Expected Outcome
The [ClientRpc] method should execute on all connected clients without errors, successfully updating the game model on each client with the serialized data passed from the host.





Environment
OS: Windows 11
Unity Version: Unity 6.0.0
Netcode Version: 2.4.3
Netcode Topology: Client-Server
Additional Context
The issue arises from the following code snippet in the GameManager class:
private void Start()
{
Model = new GameModel();
_network.ConnectionApprovalCallback = HandleConnectionRequest;
}
private void HandleConnectionRequest(NetworkManager.ConnectionApprovalRequest request, NetworkManager.ConnectionApprovalResponse response)
{
PlayerConnectionPayload connectionData = PlayerConnectionPayload.FromByteArray(request.Payload);
Model.Players[request.ClientNetworkId] = new PlayerModel
{
AvatarIndex = connectionData.AvatarIndex,
Nickname = connectionData.Nickname
};
response.Approved = true;
response.CreatePlayerObject = true;
OnModelUpdated?.Invoke();
UpdateModelClientRpc(Model.ToJson()); // This line causes the error
}
[ClientRpc]
private void UpdateModelClientRpc(string modelJson)
{
Model = GameModel.FromJson(modelJson);
OnModelUpdated?.Invoke();
}
Commenting out the UpdateModelClientRpc call prevents the error, but the RPC is essential for synchronizing the game model across clients. The problem appears to stem from invoking a [ClientRpc] within the ConnectionApprovalCallback. I’m using Unity’s Multiplayer Play Mode, which opens four editor instances simultaneously, with one instance as the host and another as the client. As a beginner in multiplayer game development, I might have misconfigured the setup or initialization order. I’m not yet fully familiar with the Netcode documentation, but the error explicitly prompted me to report this issue.