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!
asked Oct 20 '14 at 09:37 AM in Blueprint Scripting
Just in case someone is looking for a way, to get current dpi scaling in C++, here it is:
answered Apr 23 '15 at 02:51 PM
I wanted to post an up-to-date answer for getting the UMG DPI Scale at runtime. This is current to UE 4.15:
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)
answered Apr 20 '17 at 08:28 PM
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!
answered Jan 20 '15 at 06:40 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here