Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Current DPI Scaling

Hi everyone! I have LOTS of fun with UMG and I have implemented my own drag&drop. Only problem that I have is getting DPI Scaling current factor since I need proper one for my mouse position. Is there a way to get it or should I implement default DPI scaling curve ? cheerio!

Product Version: Not Selected
more ▼

asked Oct 20 '14 at 09:37 AM in Blueprint Scripting

avatar image

8 5 6 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

Just in case someone is looking for a way, to get current dpi scaling in C++, here it is:

 #include "Runtime/Engine/Classes/Engine/UserInterfaceSettings.h"
 #include "Runtime/Engine/Classes/Engine/RendererSettings.h"
 const FVector2D viewportSize = FVector2D(GEngine->GameViewport->Viewport->GetSizeXY());
 const float viewportScale = GetDefault<UUserInterfaceSettings>(UUserInterfaceSettings::StaticClass())->GetDPIScaleBasedOnSize(FIntPoint(viewportSize.X, viewportSize.Y));
more ▼

answered Apr 23 '15 at 02:51 PM

avatar image

105 13 20 30

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I wanted to post an up-to-date answer for getting the UMG DPI Scale at runtime. This is current to UE 4.15:

 // this function requires the UserInterfaceSettings header to be included
 #include Runtime/Engine/Classes/Engine/UserInterfaceSettings.h
 // this function can be marked as Blueprint Pure in its declaration, as it simply returns a float
 float MyBPFL::GetUMG_DPI_Scale() {
   // need a variable here to pass to the GetViewportSize function
   FVector2D viewportSize;
   // as this function returns through the parameter, we just need to call it by passing in our FVector2D variable
  // we need to floor the float values of the viewport size so we can pass those into the GetDPIScaleBasedOnSize function
   int32 X = FGenericPlatformMath::FloorToInt(viewportSize.X);
   int32 Y = FGenericPlatformMath::FloorToInt(viewportSize.Y);
   // the GetDPIScaleBasedOnSize function takes an FIntPoint, so we construct one out of the floored floats of the viewport
   // the fuction returns a float, so we can return the value out of our function here
   return GetDefault<UUserInterfaceSettings>(UUserInterfaceSettings::StaticClass())->GetDPIScaleBasedOnSize(FIntPoint(X,Y));

I also posted this as a gist on GitHub, which is linked on my studio's blog here: https://nacellegames.com/blog/getting-umg-dpi-scale-ue4

(Shout out to Elringus, as they were on the right track; the API has just changed)

more ▼

answered Apr 20 '17 at 08:28 PM

avatar image

644 37 49 78

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I needed to set an actor on top of some of my UMG widgets so I was facing the same issues since apparently we can't get widget world location. And so whenever the screen resolution changed, my actor was not at the relative location of my widget buttons like I wanted it. So I turned to the DPI curve, and like you, couldn't find a way to actually retrieve it using blueprints. So instead I found a way to fake it and get the desired result, although it feels a bit hack-ish, it works well.

Ok, so below I show my DPI curve in the interface settings. Using that information, I built a similar curve in a timeline. The top value is the value that tries to match the viewport size. So I have the same keyframs then in my DPI curve using the screen resolution as values. Below I have another value which aims to find the DPI scale that we need to set our actors according to screen rez. Again I used the same values then in my DPI curve i.e. 0,44444 - 0,666666 - 1.0 What is important here is that both values match in time, so that the keyframe with value 480 happens at the same time as the keyframe with the value 0.44444. Originally I had tried to set the time line to be pretty short so as not to lose to much time calculating. But this made the results innacurate as it was too frame dependant. So I stretched my 3 first keyframes to 4 seconds. The last keyframe 8 I put because it was on my DPI curve but my game doesn't use platforms that have that kind of resolution so I ignored much past 4 seconds.

So once I start the timeline, I update a compare float with my top value called DPI with the viewport size y. When the timeline finds a match (or close) it tells the timeline to stop, which leaves me with the bottom value called Scale which ends up being my DPI scale. In all trials the difference was always .1 and less of the actual value. So it isn't 100% precise, but pretty close.

With all that said, hopefully an easier way will be available in future updates. And if anyone has a better way to do it, awesome!

alt text

dpi scale trick.png (250.2 kB)
more ▼

answered Jan 20 '15 at 06:40 AM

avatar image

916 45 20 77

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question