Skip to content

[NetworkAnimator bug] Cannot re-host a game after pressing 'return to menu' from the BossRoom scene - NetworkAnimator null reference exception (does not happen after going to main menu from CharSelect or PostGame) #2044

Closed
@11BelowStudio

Description

@11BelowStudio

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

  1. Enter play mode
  2. Host via IP, click on 'host'
  3. Pick a character on CharSelect, wait for the main Boss Room scene to load
  4. Use the 'go to main menu' button within the Boss Room scene
  5. Attempt to host a new game via IP, click the 'host' button again.
  6. Error (NullReferenceException within Unity.Netcode.Components.NetworkAnimator.OnClientConnectedCallback).
    • The NetworkManager.StartHost() call succeeds, but the exception prevents CharSelect 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).

Expected behavior
The game should proceed to the 'CharSelect' scene, allowing the user to continue hosting the game as expected.

Screenshots
NullReferenceException when attempting to rehost
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 in CharSelect and PostGame 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)

Metadata

Metadata

Labels

priority:highThis issue has high priority and we are focusing to resolve itstat:importedStatus - Issue is tracked internally at Unitytype:bugBug Report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions