I’m working on ironing out some odd Session bugs with my game where sometimes the Session doesn’t get closed/destroyed properly for clients, which means that they can no longer join or host sessions afterwards. I followed Cedric Neukirchen’s C++ Sessions tutorial.
When a session is quit, it does one of two things:
- If the player is the host, it runs the ReturnToMainMenuHost() method from the GameMode, and ends the session. OnEndSessionComplete then runs DestroySession() if it was successful.
- If the player is a client, it runs ClientReturnToMainMenuWithTextReason from the Player Controller, then calls DestroySession().
Do clients need to call the EndSession method as well? I thought that only the host would have to mark the session as “ended”
In theory, only the host needs to call that function, but some issues can arise, making it unable to call the function. One way to solve those is to destroy the session whenever a player is not supposed to be in one.
For example, when the user is entering a menu or before trying to join a new session
Hey, thanks for the feedback! I was able to resolve this issue (hopefully) by using the GetSessionState function in the session interface when we load the Main Menu. If the GetSessionState function returns anything other than NoSession, I call the DestroySession method and that seems to have done the trick. Thanks for the tip!
You can also use APlayerController::ClientReturnToMainMenuWithTextReason when session was destroyed.
Edit: You are right, you need to check existing sessions before creating one. This function just does what it says, returns client to the main menu.