Download

Multiplayer - It's possible to host a session without open a new map??

Hi!!

I’m currently working (and learning about) on a multiplayer game and i’m still a bit confused. Can I create a new session without open a new map?? I’m using as code base the Shooter Example and it uses this:



	IOnlineSessionPtr Sessions = OnlineSub->GetSessionInterface();
		if (Sessions.IsValid() && CurrentSessionParams.UserId.IsValid())
		{
			HostSettings = MakeShareable(new FAPOnlineSessionSettings(bIsLAN, bIsPresence, MaxPlayers));
			HostSettings->Set(SETTING_GAMEMODE, GameType, EOnlineDataAdvertisementType::ViaOnlineService);
			HostSettings->Set(SETTING_MAPNAME, MapName, EOnlineDataAdvertisementType::ViaOnlineService);
			HostSettings->Set(SETTING_MATCHING_HOPPER, FString("TeamDeathmatch"), EOnlineDataAdvertisementType::DontAdvertise);
			HostSettings->Set(SETTING_MATCHING_TIMEOUT, 120.0f, EOnlineDataAdvertisementType::ViaOnlineService);
			HostSettings->Set(SETTING_SESSION_TEMPLATE_NAME, FString("GameSession"), EOnlineDataAdvertisementType::DontAdvertise);
			HostSettings->Set(SEARCH_KEYWORDS, CustomMatchKeyword, EOnlineDataAdvertisementType::ViaOnlineService);

			OnCreateSessionCompleteDelegateHandle = Sessions->AddOnCreateSessionCompleteDelegate_Handle(OnCreateSessionCompleteDelegate);
			return Sessions->CreateSession(*CurrentSessionParams.UserId, CurrentSessionParams.SessionName, *HostSettings);
		}


My idea is about manage the host session in the main menu, showing a window where the host can setup the map, match time and other settings, wait for people who join to this session and then choose one of these connected users (the game will be 1vs1 but a lot of players can connect until the host choose the oponent). Finally when the oponent is choosen the host push the “start” button and both travel to the gameplay map.

Is that possible?? or I should open a new level and the show the host settings window??

Thanks!

There is always a map (world) … always.

You can create a map for the lobby/mainmenu etc

Yeah, there is always a level. A main menu is just a camera in a scene of decorations (or an empty void) with 2D elements atop it.

When you want to spawn users into “the actual game”, you would write any persistent data to their GameInstance and force them to into a different map (although this can be done in multiple ways).

I’m a bit unclear about your game idea, though. Can there be multiple 1v1 matches at the same time? Or is it just a single 1v1 match, and everyone else spectates?

Either way is doable, but each way is very different from the others. Specifically, simultaneous matches requires that the main menu map sends users to a completely different server, where the game map is loaded. (You can technically also have the main menu level be the game level, but that’s a lot of weird work. GameMode, GameState, etc. would apply to all current matches and the menu… and, then, your level can only be so large, so there’s only so many play areas you can spawn in it, etc. Basically, don’t do that.)

Single matches, one at a time and everyone else spectates, can be done by "ServerTravel"ing between the menu map and the game map, back and forth, over and over, where two people are players and everyone else are spectators.

Again, if you want to persist data between levels, like RTS spawn locations, team colors, etc., you will need to write it to your subclass of GameInstance. Basically everything else is flushed when a level is changed.

(There are some exceptions with “Seamless Travel”, but it has heavy restrictions, like the GameMode cannot change.)

Yes, you can switch current loaded map to Listen server

After that remote clients will be able to connect to your advertised session :wink:

1 Like