I have created a bare minimum sample project to demonstrate the problem. Just run the attached sample project with two clients. Click Host with the first one and wait for it to get to the lobby screen. Then click Join with the second one. Wait, and you should see the lobby screen flash up for a split second before being returned to the main menu.
The reason this is happening is because the level blueprint has some nodes in it to bring up the main menu when it is loaded. So when the second player joins the session, for some reason it is triggering the level blueprint to run its BeginPlay even again. Therefore removing the lobby menu and displaying the main menu again. The player is still in the session, they are now just in the wrong menu.
So the bug (at least I’m guessing it is a bug) is that the level blueprint’s BeginPlay is being triggered when JoinSession is called. I’ve tested this now with both 4.13.2 and 4.14.0 and both have the same issue.
This is expected behavior. When you JoinSession, the level blueprint will be run again, and as a result it’s Begin Play event will run again which would explain why you are seeing the menu pop up after your client joins in. I’d recommend running a switch has authority and only running the event if authority is true to see if that works out for you.
OK, thanks Sean. However I’m not sure what you mean by running a switch has authority on it? I’ve tried placing that in the level blueprint, but then the client doesn’t load the main menu at all when the game starts. They don’t ever seem to have authority over the level.
After giving it some additional thought, I’d recommend putting any UI or lobby-related logic in the HUD class instead of using the level blueprint, as that is what the HUD class is designed for. HUD is independent to the client, and is client side only.
Give that a shot and let me know if you have any questions.
I ended up creating a new level for the lobby. The host opens it with “-listen” after creating the session and then the client automatically opens it when joining the session. So far seems to be working ok. Do you believe using the HUD and just having a single level instead would be a more reliable solution?
I think it’s fine to have a separate level for the lobby. In my test project, that is how I have it set up as well. The “Create Game” button that I have will also open the actual game level. So it sounds like you’re on the right track now.