Download

Regarding Updating Session Settings in Online Sub System

My session settings for an online game have data about the game mode and map so server browsers can display this information. When the match is over and I want to the server to travel to a new map/mode I obviously need to update this session data. I’m doing so on the server like so:


bool UBBGameInstance::UpdateSessionMapAndMode(FString NewMap, FString NewMode)
{
	IOnlineSessionPtr Sessions = IOnlineSubsystem::Get()->GetSessionInterface();
	if (Sessions.IsValid())
	{
		FOnlineSessionSettings* CurrentSettings = Sessions->GetSessionSettings(GameSessionName);
		FOnlineSessionSettings NewSettings;
		NewSettings.bIsLANMatch = CurrentSettings->bIsLANMatch;
		NewSettings.bShouldAdvertise = CurrentSettings->bShouldAdvertise;
		NewSettings.bIsDedicated = CurrentSettings->bIsDedicated;
		NewSettings.bAllowJoinInProgress = CurrentSettings->bAllowJoinInProgress;
		NewSettings.bAllowInvites = CurrentSettings->bAllowInvites;
		NewSettings.NumPublicConnections = CurrentSettings->NumPublicConnections;

		FString SessionName;
		CurrentSettings->Get(SETTING_SESSIONNAME, SessionName);
		NewSettings.bAllowJoinViaPresence = CurrentSettings->bAllowJoinViaPresence;
		NewSettings.Set(SETTING_GAMEMODE, NewMode, EOnlineDataAdvertisementType::ViaOnlineServiceAndPing);
		NewSettings.Set(SETTING_GAMEMAP, NewMap, EOnlineDataAdvertisementType::ViaOnlineServiceAndPing);
		NewSettings.Set(SETTING_SESSIONNAME, SessionName, EOnlineDataAdvertisementType::ViaOnlineServiceAndPing);
		NewSettings.bUsesPresence = CurrentSettings->bUsesPresence;

		OnUpdateSessionCompleteDelegateHandle = Sessions->AddOnCreateSessionCompleteDelegate_Handle(OnUpdateSessionCompleteDelegate);

		if (Sessions->UpdateSession(GameSessionName, NewSettings))
		{
			PRNTSCRN("First stage of updating session has succeeded, showing loading screen");
			ShowLoadingScreen();
			return true;
		}
		return false;
	}
	return false;
}

The delegate is called and I then travel to the next map with GetWorld()->ServerTravel().

Is this how this should work?

I previously had the code update the session settings and then immediately travel to the next map/mode. However this resulted in the server’s session data being lost somehow and clients were not auto travelled with the server, being instead left behind. The server would then not show up in the server browser and not be visible in anyway. As though the session had been destroyed.

I wondered, am I supposed to update the session settings on the clients as well as the server before travelling? Or will they get updated automatically? Or will waiting for the UpdateSession delegate to be called suffice so that I can travel the server and be ensured all clients will come along?