Unity-Technologies / com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.15k stars 435 forks source link

NetworkManager.DisconnectClient() is disconnecting both Client and Host. #3019

Closed Ermelious closed 3 months ago

Ermelious commented 3 months ago

Description

I’m trying to implement a function to Kick a player out of the Server, but upon adding this function to a button event:

NetworkManager.Singleton.DisconnectClient(1, "Kicked by LobbyHost.");

Logs For Client Disconnect:

Disconnected Client ID: 1
UnityEngine.Debug:Log (object)
AbstractLobbyManager/<>c:<Start>b__14_0 (ulong) (at Assets/Scripts/UI/AbstractLobbyManager.cs:72)
Unity.Netcode.NetworkConnectionManager:InvokeOnClientDisconnectCallback (ulong) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs:140)
Unity.Netcode.NetworkConnectionManager:OnClientDisconnectFromServer (ulong) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs:1028)
Unity.Netcode.NetworkConnectionManager:DisconnectRemoteClient (ulong) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs:1055)
Unity.Netcode.NetworkConnectionManager:DisconnectClient (ulong,string) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs:1085)
Unity.Netcode.NetworkManager:DisconnectClient (ulong,string) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs:1140)
AbstractStandardLobbyManager/<>c:<ListPlayers>b__6_1 () (at Assets/Scripts/UI/AbstractStandardLobbyManager.cs:236)
UnityEngine.EventSystems.EventSystem:Update () (at ./Library/PackageCache/com.unity.ugui/Runtime/UGUI/EventSystem/EventSystem.cs:530)

Logs For Host Disconnect which happens after the Client Disconnects above:

Disconnected Client ID: 0
UnityEngine.Debug:Log (object)
AbstractLobbyManager/<>c:<Start>b__14_0 (ulong) (at Assets/Scripts/UI/AbstractLobbyManager.cs:72)
Unity.Netcode.NetworkConnectionManager:InvokeOnClientDisconnectCallback (ulong) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs:140)
Unity.Netcode.NetworkConnectionManager:DisconnectEventHandler (ulong) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs:502)
Unity.Netcode.NetworkConnectionManager:HandleNetworkEvent (Unity.Netcode.NetworkEvent,ulong,System.ArraySegment`1<byte>,single) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs:396)
Unity.Netcode.NetworkConnectionManager:PollAndHandleNetworkEvents () (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs:370)
Unity.Netcode.NetworkManager:NetworkUpdate (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs:44)
Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Core/NetworkUpdateLoop.cs:192)
Unity.Netcode.NetworkUpdateLoop/NetworkEarlyUpdate/<>c:<CreateLoopSystem>b__0_0 () (at ./Library/PackageCache/com.unity.netcode.gameobjects/Runtime/Core/NetworkUpdateLoop.cs:215)

It kicks BOTH the Client with ID 1 and the Host with ID 0.

Reproduce Steps

Implement a button with the following:

playerSelectable.kickMemberButton.onClick.AddListener(() => 
                        {
                            NetworkManager.Singleton.DisconnectClient(1, "Lobby Mananger kicked.");
                        });

Actual Outcome

It should only disconnect the specified ClientID.

Expected Outcome

Upon calling NetworkManager.DisconnectClient(); it should only disconnect the specified ClientID and not the host. OR indicate what is causing the Host to disconnect. I'm still trying to figure what exactly is configured incorrectly that is causing this issue. Advice/assistance appreciated!

Screenshots

image

Environment

Additional Context

Add any other context about the problem here. Logs, code snippets would be useful here but please also consider attaching a minimal Unity project that reproduces the issue.