I’m making a multiplayer game using UE4.26. I have a GameMode class that extends GameModeBase, where on PostLogin, I assign team index to connected PlayerControllers. PostLogin works as expected.
When a player type “disconnect” into their console or alt+F4, I want to free the slot in my team array, but I cannot detect the disconnection event. Everyone says “use Logout function”, but when I extend it and put my code in, it’s never called. I put my log on every function of my GameMode class and it showed everywhere except Logout.
I test on both “Play As Client” in the editor, starting UE edtior with “-server” param, and building my own dedicated server using the special UE4 build from Github. AGameModeBase::Logout just never get called no matter how the client disconnect, reconnect, alt F4, unplug internet cable… nothing. Not called once.
.
Is this a bug only to UE4.26? Or did I miss something?
If this doesn’t work, Is there any other way I can detect player disconnection?
.
Thanks.
Since you aren’t disconnecting the client gracefully (that is, by not attempting to notify the Server you are leaving) - the Server is likely waiting for the player connection to timeout instead, before it removes the controller and calls “Logout”.
You don’t want to make that timeout too short, because then legitimatelly connected players can timeout. The best way to handle this is to add a “graceful” logout process. You could even hijack the alt+f4 command to attempt that before closing the application.
If you are using sessions, ending and destroying the session is usually enough to notify the server that a player is leaving.
At first, I thought so also, so I waited for like 15 minutes. Still, Logout not called. Can you show me where to edit the timeout amount?
For graceful logout, is this supported by UE already or I have to implement my own RPC?
Hello. Yes, I override it exactly like this. The function never called, I even waited after 2 hours since the client disconnect to make sure there is no timed out.
The pawn which the PlayerController posses isn’t even destroyed like they say it will be.
The function GetNumPlayers() still return the same number of players. (Yup, I print it to log in Tick for 2 hours straight)
Something is wrong with my unreal engine I guess.
Edit: When a client disconnect, I found this little piece of log inside Dedicated server console:
The dedicated server is well aware of a client recently disconnected. It just doesn’t do anything. Doesn’t destroy pawn, doesn’t reduce the number of player, and doesn’t call “Logout”.
Hi, Do you happen to be calling “Logout” instead of “OnLogout”?
Cuz the first one logs out the player. the second one is the one which is supposed to trigger when they log out.
Asking cuz you refer to it as “Logout” and you using this instead of the later could be the simplest of problems.
Just a minor heads up to anyone else who did not have the problem fixed by this. When a logout happens, the Pawn is destroyed first, then the logout event is performed. At least that is the order it was happening for me server side. So if there is something you want to do on a pawn that is logging out, probably need to do it in the pawn’s Destroyed event.
I was stuck on this for literal weeks and you saved me. It’s wild, Logout doesn’t get called on the Gamemode unless the playercontroller calls super::beginplay when overriding beginplay, and I had forgotten that. That’s so strange.