GSystemResolution is always zero

Reproduction Steps

  1. Create a new basic code C++ project

  2. create a new C++ class derived from Actor

  3. place the Actor in the level

  4. add the following line to the new Actor’s Tick function, compile and play

    if (GEngine) { GEngine->AddOnScreenDebugMessage(-1, 0.f, FColor::Yellow, FString::Printf(TEXT(“ResX: %f, ResY: %f”), GSystemResolution.ResX, GSystemResolution.ResY)); }

Result: GSystemResolution.ResX and GSystemResolution.ResY are 0.

Expected: GSystemResolution.ResX and GSystemResolution.ResY are equal to the resolution, that the game is running at.

Hi AllJonasNeeds,

The reason you are seeing 0.000000 outputs here is because you are formatting the string to take float values, but the values you are sending to the string are int32 values. Implicit conversion of the values does not take place in this case.

There are a couple ways that you can make this work for you. First, instead of %f, use %i in the string. This will format the string to output the integer values from ResX and ResY. Second, you could cast the values to floats if you need the output string to display float values by using static_cast< float >(GSystemResolution.ResX).

Tim