Description
Describe the bug
Using the 'return to menu' button in the BossRoom
scene causes a NullReferenceException
to be thrown by NetworkAnimator.OnClientConnectedCallback
upon attempting to host a new game. NetworkManager.StartHost()
itself works, but as this exception prevents the game from going to CharSelect
, the player, with no way of stopping the NetworkManager
, is stuck and is forced to quit the game.
To Reproduce
- Enter play mode
- Host via IP, click on 'host'
- Pick a character on CharSelect, wait for the main Boss Room scene to load
- Use the 'go to main menu' button within the Boss Room scene
- Attempt to host a new game via IP, click the 'host' button again.
- Error (
NullReferenceException
withinUnity.Netcode.Components.NetworkAnimator.OnClientConnectedCallback
).- The
NetworkManager.StartHost()
call succeeds, but the exception preventsCharSelect
from being loaded. - PopupManager does not show a 'hosting failed' error dialog in the game itself when this happens. Clicking the 'host' button again will cause the 'hosting failed' error dialog to appear (
Cannot start Host while an instance is already running
message appears in console).
- The
Expected behavior
The game should proceed to the 'CharSelect' scene, allowing the user to continue hosting the game as expected.
Screenshots
The above screenshot shows what happens after clicking on 'Host' after first clicking 'return to menu' as a host in the BossRoom
scene. As you can see, the NetworkManager
has been able to start hosting, but due to a null reference exception in NetworkAnimator
, the game itself hasn't been able to proceed to the Charselect
scene from the MainMenu
.
Environment (please complete the following information):
- OS: Windows 8.1
- Unity Version: 2021.3.3f1
- BossRoom Version: v1.3.0-pre
Additional context
- This problem only happens if you press 'return to menu' from the
BossRoom
scene. The 'return to main menu' buttons inCharSelect
andPostGame
do not have this problem. - Haven't tested if the problem affects relay connections, but chances are it will affect those as well.
- Haven't tested if it affects clients yet (whether voluntarily disconnecting or involuntarily disconnecting).
Stack trace
NullReferenceException: Object reference not set to an instance of an object
Unity.Netcode.Components.NetworkAnimator.OnClientConnectedCallback (System.UInt64 playerId) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.10/Components/NetworkAnimator.cs:446)
Unity.Netcode.NetworkManager.InvokeOnClientConnectedCallback (System.UInt64 clientId) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.10/Runtime/Core/NetworkManager.cs:352)
Unity.Netcode.NetworkManager.HandleConnectionApproval (System.UInt64 ownerClientId, Unity.Netcode.NetworkManager+ConnectionApprovalResponse response) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.10/Runtime/Core/NetworkManager.cs:2028)
Unity.Netcode.NetworkManager.StartHost () (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.10/Runtime/Core/NetworkManager.cs:1080)
Unity.Multiplayer.Samples.BossRoom.GameNetPortal.StartHost () (at Assets/Scripts/Gameplay/ConnectionManagement/GameNetPortal.cs:217)
Unity.Multiplayer.Samples.BossRoom.GameNetPortal.StartHost (System.String ipaddress, System.Int32 port) (at Assets/Scripts/Gameplay/ConnectionManagement/GameNetPortal.cs:185)
Unity.Multiplayer.Samples.BossRoom.Visual.IPUIMediator.HostIPRequest (System.String ip, System.String port) (at Assets/Scripts/Gameplay/UI/IPUIMediator.cs:83)
Unity.Multiplayer.Samples.BossRoom.Visual.IPHostingUI.OnCreateClick () (at Assets/Scripts/Gameplay/UI/IPHostingUI.cs:43)
UnityEngine.Events.InvokableCall.Invoke () (at <f1212ad1dec44ce7b7147976b91869c3>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <f1212ad1dec44ce7b7147976b91869c3>:0)
UnityEngine.UI.Button.Press () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:70)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:114)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:57)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:272)
UnityEngine.EventSystems.EventSystem:Update() (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:501)