com.unity.netcode.gameobjects icon indicating copy to clipboard operation
com.unity.netcode.gameobjects copied to clipboard

ConnectionRequestMessage was received from the server on the client side

Open p0zitived opened this issue 5 months ago • 5 comments

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<GameManager> (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.

Image Image Image Image Image

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.

p0zitived avatar Jul 17 '25 15:07 p0zitived

I've just encountered the same issue out of the blue. Put my project down for a couple of weeks, and upon picking it back up, I'm getting this error. I don't currently have any RPCs, and in fact the only data that should pass back and forth is the player's movement and animation.

#[Necode] 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: 170.
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 1a c3 60 b7 88 30 d1 55t

UnityEngine.Debug:LogError (object)
Unity.Netcode.NetworkLog:LogError (string) (at ./Library/PackageCache/com.unity.netcode.gameobjects/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/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/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/Runtime/Messaging/NetworkMessageManager.cs:397)
Unity.Netcode.NetworkMessageManager:ProcessIncomingMessageQueue () (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Messaging/NetworkMessageManager.cs:448)
Unity.Netcode.NetworkManager:NetworkUpdate (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs:340)
Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Core/NetworkUpdateLoop.cs:191)
Unity.Netcode.NetworkUpdateLoop/NetworkEarlyUpdate/<>c:<CreateLoopSystem>b__0_0 () (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Core/NetworkUpdateLoop.cs:214)

TheLordDrake avatar Aug 24 '25 16:08 TheLordDrake

Thanks for reporting this. We've not been able to reproduce this issue in order to fix this. Is there any chance you have more details about the setup of your project while this was happening?

EmandM avatar Sep 29 '25 15:09 EmandM

I'm also having some difficulty recreating the issue in a clean project.

If needed, I can supply a copy of my project. It's a ~bit messy~ (Honestly it's so small it doesn't matter) so it may not be super useful, but you can reliably reproduce the error.

TheLordDrake avatar Sep 29 '25 20:09 TheLordDrake

Being able to reliably reproduce the error would be huge for our ability to fix this. If you could supply a copy of your project we would be very grateful.

EmandM avatar Oct 01 '25 13:10 EmandM

I've uploaded a compressed copy of the project here The error only occurs when you enable Scene Management on the NetworkManager.

While removing an external package, I did discover which line in my project appears to be triggering the issue. I left a comment on it to make it easier to locate.

Image

TheLordDrake avatar Oct 01 '25 14:10 TheLordDrake