So I’ve only ever used the SEARCH_PRESENCE before when searching for sessions, however I’ve noticed that there is a query setting macro called SEARCH_MINSLOTSAVAILABLE in the OnlineSessionSettings.h file. I figured it would search for sessions that has at least x slots available. I tried using it, but for some reason I still got the session that has less than x slots available. What am I missing? Am I supposed to update the session settings for these query settings to work?
In general, I don’t really understand how these query settings work, so any explanation would help.
Here’s how I create/find sessions from a GameInstanceSubsystem.
Thanks in advance!
// Creating a new session.
FOnlineSessionSettings SessionSettings;
SessionSettings.NumPublicConnections = 4;
SessionSettings.bShouldAdvertise = true;
SessionSettings.bAllowJoinInProgress = false;
SessionSettings.bIsLANMatch = true;
SessionSettings.bUsesPresence = true;
OnCreateSessionCompleteDelegateHandle = SessionInterface->AddOnCreateSessionCompleteDelegate_Handle(OnCreateSessionCompleteDelegate);
SessionInterface->CreateSession(*PlayerId, GameSessionName, SessionSettings);
// ...
// Finding sessions.
SessionSearch = MakeShareable(new FOnlineSessionSearch);
SessionSearch->bIsLanQuery = true;
SessionSearch->MaxSearchResults = 50;
SessionSearch->PingBucketSize = 4;
SessionSearch->TimeoutInSeconds = 60;
SessionSearch->QuerySettings.Set(SEARCH_PRESENCE, true, EOnlineComparisonOp::Equals);
SessionSearch->QuerySettings.Set(SEARCH_MINSLOTSAVAILABLE, 2, EOnlineComparisonOp::Equals);
// Query settings above, should return sessions with at least 2 open slots, but it returns every session :/
// I've also tried using different comparison ops ^^
OnFindSessionsCompleteDelegateHandle = SessionInterface->AddOnFindSessionsCompleteDelegate_Handle(OnFindSessionsCompleteDelegate);
SessionInterface->FindSessions(*PlayerId, SessionSearch.ToSharedRef());
I’m going to answer my own question here. As it turns out, QUERY SETTINGS DOESN’T WORK WITH THE NULL SUBSYSTEM !!
It’s crazy that this is not mentioned anywhere.
After some more experimenting, here is a working example of Query Settings:
// Adding a new setting to the session. There are a number of predefined setting
// macros in the OnlineSessionSettings.h that you can use!
FOnlineSessionSettings SessionSettings;
SessionSettings.Set(SETTING_GAMEMODE, FString("Deathmatch"), EOnlineDataAdvertisementType::ViaOnlineService);
// Adding a new query setting to search. There are additional predefined search
// macros in the OnlineSessionSettings.h that you can use as well.
SessionSearch = MakeShareable(new FOnlineSessionSearch);
SessionSearch->QuerySettings.Set(SETTING_GAMEMODE, FString("Deathmatch"), EOnlineComparisonOp::Equals);
// Checking a session's settings. This will work even with the Null Subsystem!
// Make sure to read the session from somewhere. For example, after
// finding sessions have completed.
FOnlineSessionSearchResult SearchResult;
FString GameModeString;
if (SearchResult.Session.SessionSettings.Get(SETTING_GAMEMODE, GameModeString))
{
// GameModeString has been populated with the proper data.
// At this point you can do whatever you want with it.
}
Hey thanks for the info. I’m a little confused at the last code-block example, any help is appreciate
Do you have to check the SessionSettings after finding sessions? I ask because I feel like that defeats the whole purpose of QuerySettings. Shouldn’t sessions that strictly match the query be returned?