Join or Open Level to dedicated server doesn't work on BeginPlay, but does on user input

I’m running a dedicated server and in order to join straight away I set up a bootstrap level that connects to the server on BeginPlay. I tried using the Open Level node (with IPaddress + port), or an Execute Console Command node (with ‘open IP + port’), in either the level blueprint or player controller blueprint. Both crash the editor with no clear log/error message; also after a delay. Note that I do see a new connection succesfully joining the server, but it seems the moment it needs to load the map on the client it crashes.

But when I simply type in ‘open IP:port’ in editor after hitting play using the Tilde (~) key it correctly joins the dedicated server. Same for when I try to connect to the server after the user presses a key. Both have the exact same logic, yet it won’t work on BeginPlay. What’s the difference?

Something interesting to note that on the server it seems to suggest the player joins with the request of a different map (I don’t need to specify the map as the server is already on a fixed map). Nevertheless, the same happens after user input so I’m not sure it’s too relevant.

Thank you,
// Joey

hey Joey, you’ve referenced BeginPlay() but you haven’t stated what actor’s BeginPlay() you are talking about. It will help to know in what BeginPlay() you’re using for that, some object’s won’t call it when you think and the GameMode will not be on the clients in the first place.

Hey Devlyn, I’ve tried it in both the Bootstrap’s level blueprint, and a custom playercontroller’s blueprint (making sure ownership is correct in case that’s relevant).

I’ve figured out what was happening; maybe this will help someone else as well. I’ve been running a dedicated server for the whole project and as a result I’m always hitting Play with Net Mode set to ‘Play As Client’. Of course this meant the Bootstrap map also spawns a dedicated server which would then run the same BeginPlay events, thus the server would swap levels with the client still connected (and probably also traveling at the same time), crashing the engine.

This was easily solved by a simple ‘Is Server’ or ‘Is Dedicated Server’ branch on False. (Or just run Net Mode as ‘Play Offline’ in the bootstrap map).

That’s great news! Thanks for the update and the solution!

1 Like