FindSessions MaxSearchResults = 1 return more than 1

I don’t know if it is a bug, but when I specify MaxSearchResults = 1; in the SearchSettings and FindSessions, it returns more than one element in the SearchResults array.

Is this member var used in FindSessions to limit the number of results ?

IOnlineSessionPtr OnlineSessionInterface = OnlineSubsystem->GetSessionInterface();

		SessionSearchSettings = MakeShareable(new FKOnlineGameSearchBase(false));
		SessionSearchSettings->MaxSearchResults = 1;
		FString GameVer = FString::Printf(TEXT("%i"), FNetworkVersion::GetLocalNetworkVersion());
		SessionSearchSettings->QuerySettings.Set(SETTING_SERVERVERSION, GameVer, EOnlineComparisonOp::Equals);			SessionSearchSettings->QuerySettings.Set(SETTING_SERVERINSTANCEGUID, JoinCurrentGUID, EOnlineComparisonOp::Equals);	// The GUID to find
		TSharedRef<FKOnlineGameSearchBase> SearchSettingsRef = SessionSearchSettings.ToSharedRef();

		if (OnlineSessionInterface.IsValid())
		{
			OnlineSessionInterface->CancelFindSessions();
		}

		OnFindGUIDSessionCompleteDelegate.BindUObject(this, &AKBasePlayerController::OnFindSessionsComplete);
		OnFindGUIDSessionCompleteDelegateHandle = OnlineSessionInterface->AddOnFindSessionsCompleteDelegate_Handle(OnFindGUIDSessionCompleteDelegate);

		OnlineSessionInterface->FindSessions(0, SearchSettingsRef);

In the OnFindSessionsComplete the array has 2 elements.

void AKBasePlayerController::OnFindSessionsComplete(bool bWasSuccessful)
{
	if (bWasSuccessful)
	{
		// Clear the delegate
		IOnlineSubsystem* OnlineSubsystem = IOnlineSubsystem::Get();
		if (OnlineSubsystem && SessionSearchSettings.IsValid())
		{
			IOnlineSessionPtr OnlineSessionInterface = OnlineSubsystem->GetSessionInterface();
			OnlineSessionInterface->ClearOnFindSessionsCompleteDelegate_Handle(OnFindGUIDSessionCompleteDelegateHandle);

			int32 count = SessionSearchSettings->SearchResults.Num();

			UE_LOG(LogDebug, Log, TEXT("AKBasePlayerController::OnFindSesssionComplete  -  SessionSearchSettings->SearchResults.Num=%i"), SessionSearchSettings->SearchResults.Num());

count = 2

Regards,
D.

Hi domzorg,

I apologize for the delay in responding to this post. I just wanted to let you know that we are looking into it and will get back to you soon.

So sorry for the delay in a response.

The MaxSearchResults value should be respected, but most likely at the moment we are relying on the back end services to respect the value.

Last I knew all backends did take such a parameter so there was no need for client side filtering.

What platform are you using so we can get someone to look into this?

I’m using the Null subsystem. But I debug the code, I didn’t saw any code filtering the result.

So sorry for the delay on the followup.

You are correct, the NULL interface isn’t respecting the value. Shame on my code inconsistencies.

You can change the code here

void FOnlineSessionNull::OnValidResponsePacketReceived(uint8* PacketData, int32 PacketLength)

// Add space in the search results array
FOnlineSessionSearchResult* NewResult = new (CurrentSessionSearch->SearchResults) FOnlineSessionSearchResult();

To make it check the max search results and stop adding new results.

This code waits N seconds for broadcast packets from other LAN servers before returning all server responses. The NULL interfaces is more of a mocking/testing interface. Each server broadcasts its presence and therefore we don’t have a good filtering system in place for it.

The server could filter based on the request, or the client could filter based on the response. I’ll make a ticket to address this, but I can’t guarantee a timeline for it.

Ok. thanks for your explanations.

Hi! 7 years later…was this solved?

Does NULL interface respect the MaxSearchResults and TimeoutInSeconds?
I want to make it run on a local LAN with just 4 computers and want to avoid
that 5 seconds wait for just finding the server.

If so…any workaround?
Thanks!

Dany