Can not set resolution with the specify value

Hi.
I am working on a demo.
I want to make a combo box to select a resolution and set it.
I get the resolutions array with RHIGetAvailableResolutions();
And I use UGameUserSettings->SetScreenResolution() to set it.
It can not set up most resolutions.
But I can use the command to set the resolution, just like “r.setres 1024x768”.
Can anyone tell me why?

Here is my code:

void UDemoBlueprintLibrary::SetCustomResolution(const FString& InStr)
{
UGameUserSettings* Settings = GEngine->GetGameUserSettings();

FString TempStr = ClearResolutionString(InStr);

int32 StrIdx = TempStr.Find("*");

if (StrIdx != INDEX_NONE)
{
	if (Settings)
	{
		int32 X = FCString::Atoi(*TempStr.Left(StrIdx));
		int32 Y = FCString::Atoi(*TempStr.Right(StrIdx));
		FIntPoint CustomResolution(X, Y);
		
		Settings->SetScreenResolution(CustomResolution);
		Settings->ApplySettings(true);
	}
}

}

I had the same problem. The fix is to set fullscreen mode to windowed. And make sure apply settings parameter is false. Like this:

// Set the new resolution
GameSettings->SetFullscreenMode(EWindowMode::Windowed);
GameSettings->SetScreenResolution(FIntPoint(X, Y));
GameSettings->ApplySettings(false);