When to create a Session?

I’m trying to implement sessions, but I haven’t been able to find a good place to create the session in the first place. The examples I’ve seen, including ShooterGame, create the session from the menu. Doing this seems odd, as I’m fairly certain it means that a multiplayer game wouldn’t function correctly unless it was explicitly created by the menu. Using ‘open’ would be odd, but it is possible. I’m fairly certain the command line could also be used to start a server, e.g. for a dedicated instance.

Is there a better place to create the session? I’m trying with the GameInstance, since that should persist between map changes, but doing it in Init() isn’t working, although I’m not sure why.

It would really depend on your project.
I would suggest connecting to the server (joining the “lobby”), then having players either create sessions (“rooms”/“games”) or join other sessions. But that’s just a general thing, and like I said it would depend on your project.

I believe that is what I’m going for. I guess my question is more implementation specific. As in, what event do I use to catch the initial multiplayer hosting (e.g. as a listen server) but without firing on every map change? From my understanding, the session should persist between map changes, hence me trying to create it in the Game Instance.

You mean you don’t want it to try and reconnect on every map change?

You could have a “connect to main server” map (completely empty, or a clone of another) and have it change once it connects. Then it wouldn’t fire twice.

But a better idea would be to have a persistent boolean that needs to be false in order to “reconnect”/connect to the server, and set it to true when it connects.

I don’t believe so. But maybe I’m just misunderstanding how sessions are supposed to work. This is for a multiplayer FPS, and from what I’ve seen, most FPSes seem to work in the same general way.

A player gets a list of sessions and selects one. This is used to connect to the actual server. Player plays with the other players already in the server, and the score/time limit is reached. The server transitions to a new map, bringing all connected players to the new map. At no point does the session disappear from the list on the master server (e.g. the steam subsystem).

From my understanding, the session object does not change, only the state (via StartSession, EndSession - both of which are called by GameMode, in SetMatchState()). So I need to create the session on hosting, and have it persist until the server goes down.

For something like that, what would actually happen is this…

A player would connect to the server, create a session, and then people would join him in a “lobby” map until the match was ready to start (however you control that).
When the match is ready to start, the “host” (the player hosting the session) would change maps (your code/bp would have that happen properly) and the others would /automatically/ join in on the map.
Anyone who joins later (if you allow that), would be immediately up to speed on the correct map and could join in however you make it happen.

When the timer runs up or whatever causes the match to end, the map could be changed back to the “lobby” map (automatically, by the host the same way it changed to the “match” map) and all the players would remain.

You would use the persistent data to control the playernames, but you could also use it for things such as what team they’re on.
The different maps would read the data on the “GameInstance” (such as… Red Team) and process that data how you do it.

So, the “match” map would see they’re on the red team and spawn them on the red side. It could also read any appearance data and adjust their clothing and items and such

It honestly sounds like we’re talking about different things.

Using the first person template, or probably any template system, I believe it is possible to start up two instances. Have the first type open example_map?listen and the second open This will put them on the same map. Were there additional game rules in place, they could wait for the time to runout and transition to the next map, using seamless travel to go together.

That is basically what I’m looking for, only using sessions to replace the open Player A starts a listen server through whatever mechanism, e.g. open example_map?listen. This automatically creates a session that persists for the entire duration of the listen server. Player B uses a menu to find that server, ultimately doing the same as the earlier open command.

That’s all I need right now. I can worry about lobbies later.

“Open” is what connects to the server. If you do that with 2 clients, yes they will be on the same map. But the MOMENT another client connects, they will be thrown into the same map, playing with the other 2 players.

This is where the sessions come in. You have to have the server do ?listen, but then that map needs to be a lobby where they can make and join rooms.

I don’t understand why a lobby is necessary.

But the MOMENT another client connects, they will be thrown into the same map, playing with the other 2 players.

That is what I want to happen.

You want all clients to immediately join the single-existing match, when they connect? If so, then you don’t even need to worry about sessions

So, I am completely misunderstanding the point of sessions? They cannot be used to implement a server browser?

You could do that, but they’d all be connected to the “main server”, they wouldn’t be stand alone versions and you’d need to connect to the main server to access them

You could do that, but they’d all be connected to the “main server”, they wouldn’t be stand alone versions and you’d need to connect to the main server to access them

EDIT: Also, each “server” would be created by clients, unless you made the sessions yourself. But at that point, you’d also be a player in that server