Leave Game Error After WInning

Hello everyone,

I’m not entirely sure when this issue may have cropped up, but only stumbled upon it now that I’ve finished the lobby display lecture. It seems as though starting and playing the game works perfectly, but after a player wins and the host hits the leave game button there is an error and the player is unable to leave the game. Meanwhile the joiner is removed from the game properly.

Note: This seems to only happen if the host hits leave game first!

Small update: I cloned the repo that was available on the course’s GitLab and it seems like the issue is there as well (as well as one where the aim-at point wasn’t set on the unit base for some reason but that was a quick fix).

So this leaves me to wonder if its related to my version of Unity (Unity 2020.1.17f1) or something else.

There is a bug related to the GameOverDisplay and GameOverHandler not calling their OnServerStop() methods. This could be related. I would try moving the code from OnServerStop to OnDestroy() (you will need to add this callback) and see if that helps.

What version of Mirror are you using?

Hello Yitzchak,

Sorry for the confusion but do you mean moving the unsubscribes performed in GameOverHandler’s OnStopServer() method and put them inside a OnDestroy() method?

image

Also excuse me if I’m being daft but I attempted to delete mirror and reimport a fresh copy of mirror as the Steam lecture suggests but it looks like I’m running with Mirror version 30.5.3 even though I “should” have the latest version the package manager claims being 35.1.0. Either way the issue still persists :frowning:

Yes, where the callback is OnStopServer, just change that to OnDestroy(), since OnStopServer never gets called.

For Mirror, I generally advise to delete the entire Mirror folder and do a fresh import. For some reason it has trouble when importing a new version in overriding the existing files.

Oh I see what you mean now. I tried your suggestion on swapping OnStopServer for OnDestroy but it seems like the issue persists. I also double checked my Mirror and deleted the entire folder before doing a fresh import again just to make sure.

Can you should the line of the code in the script that the error refers too?

Of course
image

Can you add some debug.log() statements in there to check which variable is causing the null reference.
Could be conn, conn.identitiy or the RTSPlayer.

Not sure if I troubleshooted this properly but I think you may be onto something. These are the results after running the following debug logs. The Nulls stand out but I see Null on both of the player instances so I’m not entirely sure what to make of it.
image

It’s running on server disconnect twice? Once for each player in the game?

That’s actually a good call, to be entirely honest I thought that’s how it would typically work for each client side of the game. I’m not sure what would be causing it to run more times than necessary.

Edit: I just found this article that seems to be relevant. If I understand right this is a bug on Mirror’s end that they will be fixing? https://github.com/vis2k/Mirror/issues/2706

I found Mirror’s latest version on their GitHub (It hasn’t been pushed to the asset store yet) and it somewhat solves the issue. The host can leave the game properly but you will have a few other issues coming up unrelated to Mirror and more on the older code in the course.

Edit: Forgot the link https://github.com/vis2k/Mirror/releases

It doesn’t seem to like the minimap Network identity check back in Minimap.cs but other than that the disconnection aspect is working fine.


Edit: A solution to this is to simply add [ClientCallback] to the Minimap.cs Update method.

Thank you Yitzchak for troubleshooting shooting this issue with me! You pointing out the disconnect function running twice helped me a lot!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms