How to get the DPI Scale of UMG UI in Unreal Engine 4

Hello everyone! Here's a short technical post aimed at other Unreal Engine 4 developers.

The current project our studio is working on requires us to know the DPI Scale the Engine is using to render Unreal Motion Graphics (UMG) User Interface widgets on screen. We need this information so we can make adjustments to our game based on the UMG DPI Scale.

As of Unreal Engine version 4.15, there's no way to get this information natively from within Blueprint, but there is a way to get it by writing a simple C++ function in a Blueprint Function Library.

Here is the function:

We wanted to share this code in hopes it'll help out another Unreal Engine 4 developer. Also, a shoutout to Unreal AnswerHub user "Elringus" as they posted an example of using the Engine APIs required to write this function.

Let us know in the comments if this helped you out on your project.

Until next time!