Why is the client's level reloaded when the server runs OpenLevel?

Hi!

This is the first time I develop a multiplayer game. It’s a prototype: I’m learning how to develop multiplayer games.

I’m using the listen server model with two players: the listen server and the client.

The first level of game is an empty game with a blueprint widget to set player’s name:

There is a GameMode for this empty level, and another GameMode for the rest of the levels.

When the player hits Enter it does this:

But, when it OpenLevel in the Server, the client’s blueprint widget to set name reloads again and now running as a server. So, this node never runs:

imagen

Now I’m testing it this way:

I have tried also this configuration:

But both run as server (Has Authority is always true).

Why is the client’s level reloaded when the server runs OpenLevel?

How can I fix it?

Thanks!

The behavior you experience is due to the Editor already made a connection and when the server opens a level the already connected client tries to follow.


When you select the Net Mode Play Standalone no connection is made for you

When you select the Net Mode Play as Listen Server the first instance will launch as a listen server and additional players will auto-connect to this listen server.

When you select the Net Mode Play as Client a dedicated server instance will launch and every player will auto-connect to the dedicated server.


If you want to test the joining server flow in Play In Editor (PIE) mode you should select “Play Standalone” to avoid the auto-connect feature of the other Net Modes.


Let’s assume you test with 2 standalone players.

Before either of the players have created or joined a server it is safe to assume that you are standalone (Not connected to anything) so you don’t need to do any authority checks here.
If you want to be sure anyway you can use the “Is Standalone” node which should return true on both players.

Now by using a widget and a button you can let the players either do the OpenLevel with levelname and “listen” option or the IP for joining.

Now use the “Output log” to debug if things go right or wrong.


When the first standalone player attempts to create a listen server you should see something like this in the log.

listening on port 7777

When the second standalone player attempts to join the server the server should see this in the log.

Join succeeded

Now that you established connection between both players “Is Standalone” should return false on both players.

Now you can begin to use “Has Authority” on replicated Actors spawned by the Server to branch listen-server and client logic.

Hope this helps

Thanks a lot!

But, what happens if both players try to OpenLevel with levelname and “listen” option?

My problem is that I don’t know if there is already a server listening to a connection. This is why I though to use a session, and the first thing to do before try to create one is look a session. If there isn’t any try to create it.

Thanks again.