Hello,
I’m encountering a bug in my game where I’m unable to create a new lobby after playing a game. The issue seems to occur only when I’ve already played a match, as it works fine when I haven’t played any matches yet.
The error message I received is as follows:
NullReferenceException: Object reference not set to an instance of an object
Unity.Netcode.NetworkBehaviour.__endSendClientRpc (Unity.Netcode.FastBufferWriter& bufferWriter, System.UInt32 rpcMethodId, Unity.Netcode.ClientRpcParams clientRpcParams, Unity.Netcode.RpcDelivery rpcDelivery) (at Library/PackageCache/com.unity.netcode.gameobjects@1.4.0/Runtime/Core/NetworkBehaviour.cs:202)
LobbyManager.UpdatePlayerClientRpc (System.UInt64 clientId) (at Assets/Scripts/MainMenu/Network/Lobby/LobbyManager.cs:114)
LobbyManager.PropagateToClients () (at Assets/Scripts/MainMenu/Network/Lobby/LobbyManager.cs:107)
LobbyManager.OnClientConnectedCallback (System.UInt64 playerId) (at Assets/Scripts/MainMenu/Network/Lobby/LobbyManager.cs:96)
Unity.Netcode.NetworkManager.InvokeOnClientConnectedCallback (System.UInt64 clientId) (at Library/PackageCache/com.unity.netcode.gameobjects@1.4.0/Runtime/Core/NetworkManager.cs:446)
Unity.Netcode.NetworkManager.StartHost () (at Library/PackageCache/com.unity.netcode.gameobjects@1.4.0/Runtime/Core/NetworkManager.cs:1021)
LobbyManager.CreateLobby (LobbyData data) (at Assets/Scripts/MainMenu/Network/Lobby/LobbyManager.cs:58)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <3dd5df5ef4974f29afeb2d3ba227c5da>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <790a43858b4b404fbe02a2b7b4a0d9d6>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <790a43858b4b404fbe02a2b7b4a0d9d6>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <790a43858b4b404fbe02a2b7b4a0d9d6>:0)
Here is the code that triggers leaving the match:
public async void QuitToMainMenu()
{
await MatchmakingService.LeaveLobby();
NetworkManager.Singleton.Shutdown();
SceneManager.LoadScene((int)SceneIndexes.TITLE_SCREEN);
}
I already tried a lot of things, but I’m lost.
I would appreciate any insights or suggestions on how to resolve this issue. If you need any additional information or code snippets, please let me know, and I’ll be happy to provide them.
Thank you in advance for your assistance.
- Wesley
Unity version: 2022.1.18f1
Netcode for Gameobjects version: 1.4.0
Lobby: 1.0.3
Relay: 1.0.5