0
\$\begingroup\$

I am making a settings menu. This includes a combo box where you can change the refresh rate setting.

How do I find out the maximum allowable refresh rate of the current user's monitor, using Blueprints?

\$\endgroup\$
2
  • \$\begingroup\$ Why would you want that information? If you are making a settings window, why not allow some standard values (maybe from 30FPS to 200FPS?) and let the user decide what's best for them? \$\endgroup\$
    – TomTsagk
    May 14 '20 at 11:19
  • \$\begingroup\$ @TomTsagk I don't want the user to be able to select a refresh rate that their monitor cannot handle - seems unprofessional where an easy solution exists \$\endgroup\$
    – Natalo77
    May 15 '20 at 8:30
1
\$\begingroup\$

From the docs, it looks like you can use the FScreenResolutionRHI data structures fetched by RHIGetAvailablrResolutions, each of which reports a refresh rate.

There's a code sample on this wiki page that looks useful:

static FORCEINLINE void GetDisplayAdapterScreenResolutions(FScreenResolutionArray& Resolutions) { 
    if (RHIGetAvailableResolutions(Resolutions, false)) { 
        for (const FScreenResolutionRHI& EachResolution : Resolutions) { 
            UE_LOG(YourLog, Warning, TEXT("DefaultAdapter - %4d x %4d @ %d"), EachResolution.Width, EachResolution.Height, EachResolution.RefreshRate);
        } 
    } else { 
        UE_LOG(YourLog, Error, TEXT("Screen Resolutions could not be obtained")); 
    } 
}
\$\endgroup\$
4
  • \$\begingroup\$ I definitely should have mentioned this before, but is there any way to access these structs in BPs \$\endgroup\$
    – Natalo77
    May 14 '20 at 14:25
  • \$\begingroup\$ Agreed, that should be in the original question. 😉 At minimum, you should be able to create a custom Blueprint node that accesses this info, but I can't advise on anything built-in. \$\endgroup\$
    – DMGregory
    May 14 '20 at 14:44
  • \$\begingroup\$ nerivec.github.io/old-ue4-wiki/pages/… This seems to provide a basic C++ Function Library to expose the functionality to Blueprints - I'll put up an answer tomorrow, or you can incorporate it into yours, so there is one correct answer. \$\endgroup\$
    – Natalo77
    May 14 '20 at 16:56
  • \$\begingroup\$ Great find! I recommend posting your own answer, since you're in a better position to test it or capture relevant blueprint screenshots. I don't have Unreal installed atm, so what I've written above is just based on the first page of search results. \$\endgroup\$
    – DMGregory
    May 14 '20 at 16:59
0
\$\begingroup\$

Upon consultation with external sources, I came across this code for a C++ function library that exposes the functionality in DMGregory's answer to Blueprints:

https://nerivec.github.io/old-ue4-wiki/pages/get-available-screen-resolutions-in-blueprints.html

The post reads:


Get Available Screen Resolutions in Blueprints

Contents

  1. Overview
  2. Code

    2.1. Header File

    2.2. Cpp File

Overview

The following Blueprint Node is based on the function provided by Rama, see . The provided function has the limitation that you cannot use it in your own Blueprint Library. The reason is because the FScreenResolutionRHI Type is not a BlueprintType. As I required such a function for my options UMG widget I wrote it, tested it and decided to share it.

Code

The following code is meant to be included in your own Blueprint Library. If you do not know how to make a Blueprint Library I recommend you read

Header File

First you declare the new FScreenResolutionRHI type. As mentioned in the comments it is not an exact duplicate of FScreenResolutionRHI. The reason is that when I used uint32 I was not able to use break or make nodes. My guess is that the Blueprint's Integer Type is defined as int32 in c++ and thus is not compatible with uint32. If someone can confirm this feel free to do.

/**
 * Screen Resolution
 * @remark Engine type is not meant for blueprints so we replicate the type.
 * @remark The Engine type uses uint32 but we need to use int32. Otherwise it won't be possible to break/make this type.
 */
USTRUCT(BlueprintType)
struct FScreenResolutionRHIBP
{
    GENERATED_USTRUCT_BODY()

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = ScreenResolution)
    int32 Width;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = ScreenResolution)
    int32 Height;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = ScreenResolution)
    int32 RefreshRate;

    FScreenResolutionRHIBP()
    {
        Width = Height = RefreshRate = 0;
    }
};

/**
 * Retrieve a sorted list of all screen resolutions supported by the player's display adapter.
 *
 * @returns the array of all supported screen resolutions.
 */
UFUNCTION(BlueprintPure, Category = Utility)
static TArray<struct FScreenResolutionRHIBP> GetDisplayAdapterScreenResolutions();

Cpp File

#include "RHI.h"

...

TArray<FScreenResolutionRHIBP> YourBlueprintLibrary::GetDisplayAdapterScreenResolutions()
{
    TArray<FScreenResolutionRHIBP> ResolutionsToReturn;
    FScreenResolutionArray Resolutions;
    if (RHIGetAvailableResolutions(Resolutions, false))
    {
        // Preallocate just enough memory to store all elements
        ResolutionsToReturn.Reserve(Resolutions.Num());

        for (const FScreenResolutionRHI& EachResolution : Resolutions)
        {
            FScreenResolutionRHIBP resolution;
            resolution.Width = EachResolution.Width;
            resolution.Height = EachResolution.Height;
            resolution.RefreshRate = EachResolution.RefreshRate;

            ResolutionsToReturn.Add(resolution);
        }
    }

    return ResolutionsToReturn;
}

Enjoy!

-- ( ) 13:27, 18 January 2015 (UTC)

\$\endgroup\$
2
  • 1
    \$\begingroup\$ This answer is currently link-only. If that page ever moves or becomes unavailable, future users won't be able to get much from this answer. Can you edit your answer to include at least a rough overview of how to put this solution into practice, so even if the link rots it still points future users in a fruitful direction? \$\endgroup\$
    – DMGregory
    May 15 '20 at 11:17
  • \$\begingroup\$ Yeah I'll get on that later \$\endgroup\$
    – Natalo77
    May 15 '20 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.