#Multiplayer - Unable to rejoin a lobby

1 messages · Page 1 of 1 (latest)

whole acorn
#

So I'm trying to make an online multiplayer game using Unity Netcode for GameObjects - Distributed Authority, and strangely enough I noticed that when a player leaves a lobby, then rejoins that same lobby, the error listed below* shows up. Some extra info, I got this working with unity's multiplayer packages, I'm running unity6.1, I'm quite new to game dev (less than a year), but moreso to online multiplayer, this is my first project.

When the initial host of a lobby tries to rejoin a lobby, they simply can't, but also don't get shown the start ui anymore where they can select another lobby. They just get stuck

When a non-host leaves the lobby and rejoins, the same error shows up, but this time the player is able to partially enter the lobby. They can be seen by other players, but their "disconnect" button is non-interactable, they don't show a code at the top and they can't chat. They also don't have a camera object in them yet still are able to look around which is incredibly weird.

This is an issue that seems to randomly have popped up as it didn't happen before. It's possible that I might have changed something, but I would have no clue as to what. I don't think changing code would be the best way to fix it, as this system used to work fine with rejoins before.. But I'm not experienced enough to be certain about that..

If anyone would be as kind as to point me in the right direction, I would be very, very grateful!
Thank you!


`ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.

Parameter name: index

System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <d6e80b37d98246a5859a00c653f9fdf3>:0)

Unity.Multiplayer.Widgets.WidgetEventDispatcher.OnSessionJoined (Unity.Services.Multiplayer.ISession session, Unity.Multiplayer.Widgets.WidgetConfiguration widgetConfiguration) (at ./Library/PackageCache/com.unity.multiplayer.widgets@8f9a1d20b6e1/Runtime/Core/Base/Widget/WidgetEventDispatcher.cs:148)

Unity.Multiplayer.Widgets.SessionManager.set_ActiveSession (Unity.Services.Multiplayer.ISession value) (at ./Library/PackageCache/com.unity.multiplayer.widgets@8f9a1d20b6e1/Runtime/Session/Session/SessionManager.cs:35)

Unity.Multiplayer.Widgets.SessionManager.EnterSession (Unity.Multiplayer.Widgets.EnterSessionData enterSessionData) (at ./Library/PackageCache/com.unity.multiplayer.widgets@8f9a1d20b6e1/Runtime/Session/Session/SessionManager.cs:128)

Unity.Multiplayer.Widgets.EnterSessionBase.EnterSession () (at ./Library/PackageCache/com.unity.multiplayer.widgets@8f9a1d20b6e1/Runtime/Session/Widgets/Base/EnterSessionBase.cs:78)

System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <d6e80b37d98246a5859a00c653f9fdf3>:0)

UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <2c271b216ff84328b73d1d7f2333e7ab>:0)

UnityEngine.UnitySynchronizationContext.Exec () (at <2c271b216ff84328b73d1d7f2333e7ab>:0)

UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <2c271b216ff84328b73d1d7f2333e7ab>:0)`

crystal grove
#

@whole acorn

#

You'll need to make something that resets NetCode Status when you leave.

#

(And btw, how do you got Unity as Discord presence?)

crystal grove
whole acorn
#

App activity tab

crystal grove
#

Right now you can see Visual Studio on my activity but not Unity..

whole acorn
crystal grove
#

Just a cleanup function to reset the Netcode status when a player leaves

crystal grove
#

@whole acorn Could you tell me when its fixed? So I can know if you need extra help

whole acorn
crystal grove
#

Try to only use public methods

whole acorn
crystal grove
#

internal → public and remove sealed basically

whole acorn
#

Thus I can't really modify the protection levels

#

Would it be a good practise to embed the whole multiplayer package so that I can safely make changes in it?

crystal grove
whole acorn
#

Because if I modify the package script's protection levels, the next time I boot up unity, it'll be undone again

crystal grove
whole acorn
# crystal grove You can try it.. , it depends on how you'll do it

So I discovered something new. The error is actually caused by another script I have that disables the widgets depending on whether or not the player is in a lobby.. But the issue is still partially there as if the lobby owner leaves the lobby and rejoins, they only get connected to the chat but don't actually get instantiated with a player prefab.. I also don't see any logs about ownership of the lobby being transfered to the next player.. Maybe that's why? I'm just theorizing here..

crystal grove
whole acorn
crystal grove
whole acorn
crystal grove
#

use LobbyService.Instance.GetLobbyAsync(lobbyId); then look for lobby.HostId

whole acorn
#

thanks, I'll try that

crystal grove
#

if lobby.HostId is the same then the ownership isn't transferred

whole acorn
#

Alright, finally got it working. Took me a while haha. So here's what I got.

When the host leaves, the ownership is not carried over to another player, because the game doesn't detect any other players in the lobby to carry over the ownership to..

#

So after the lobby owner leaves, there is no owner anymore

#

I'm now going to test and see what happens if an ordinary player attempts to join a lobby where the initial owner has left

#

Okay, so I found out that the ownership DOES actually get carried over, my bad. But once the initial owner leaves, nobody else can join that lobby(, or well.. Partially I'll explain). Even though ownership has been carried over to another player

When a player joins a lobby where the initial owner leaves from, they can use the chat system and others can see their messages, but they just don't get a player prefab which they can move and look around with

#

I have no clue where to go from here honestly..

crystal grove
#

@whole acorn Does it work perfectly now?

#

My bad for the late reponse.. was working.

whole acorn
crystal grove
#

Can you share me the code in a textfile?

whole acorn
crystal grove
whole acorn
#

But I got the Session Manager, Network Manager.. Any of those?

crystal grove
whole acorn
#

Alright, thank you! Here's the two scripts. The SessionManager has been partially (and temporarily) modified for the debugs to figure out whether the ownership was being carried on

crystal grove
#

Of course it doesnt work lol

#

@whole acorn first of all: put AutoSpawnPlayerPrefabClientSide on true

whole acorn
whole acorn
#

serializedfield

crystal grove
#

OnFetchLocalPlayerPrefabToSpawn then AutoSpawnPlayerPrefabClientSide on true

whole acorn
#

I'll try it

crystal grove
#

I think it does wait

#

if it's not working you probably have to add a Distributed Authority script

whole acorn
#

How do I enable the AutoSpawnPlayerPrefabClientSide within the script? Probably a stupid question but I don't quite see a variable for it set to false

#

or do I make the variable myself and set it to true?

crystal grove
#

or just paste this one , i just edited it: void Awake() { if (NetworkManager.Singleton != null) { NetworkManager.Singleton.NetworkConfig.AutoSpawnPlayerPrefabClientSide = true; NetworkManager.Singleton.OnFetchLocalPlayerPrefabToSpawn = () => { return NetworkManager.Singleton.NetworkConfig.PlayerPrefab; }; } }

whole acorn
#

Thank you! I'll try that!

crystal grove
whole acorn
#

Alright so I tested it, unfortunately doesn't work yet, but I'ma keep trying some stuff, see if just maybe I'll get it to work. Thank you!

crystal grove
crystal grove
whole acorn
crystal grove
whole acorn
crystal grove
#

Like theres no way that its not possible

whole acorn
crystal grove
#

Theres just something wrong.

whole acorn
crystal grove
whole acorn
#

Should I add you to the github repository?

crystal grove
#

That would be better

whole acorn
#

Alright, wait is it okay if we continue talking in dm's?