0
\$\begingroup\$

On mobile, I was planning on using Screen.dpi to work out the physical size of the screen and size controls accordingly.

enter image description here

But this quick test on my Galaxy S5 proves that the numbers from Unity are wrong.

1080 / 480 = 2.25 But the screen in real life is over 2.5 inches high.. So this is way off.

Any suggestions..? Right now I think I'll just leave this, and have the controls the same size in world space.. rather than risk making them worse.

\$\endgroup\$
0
\$\begingroup\$

See here and here.

The gist is that on Android devices specifically, the values returned from Screen.dpi are often off because Android doesn't have the same info available (or in the presumed format) for Unity to crunch. So Unity forces the function Screen.dpi to call densityDpi instead. This method returns constant DPI densities provided by the manufacturer. They may be off by a little or a lot.

That second forum post link is provided by a Unity developer (back in 2013) and they offer a potential workaround function you can use instead of Screen.dpi (though it is not guaranteed). They also list phones where there WERE issues and phones were there were NOT issues. Unfortunately, it being 7 years later now, you will be swinging in the dark a little.

All this being said, the DPI of your phone should be publicly available via a simple Google search. When you find it, just multiply the density by the screen width to get the number of pixels horizontally, and multiply the density by the screen height to get the number of pixels vertically. The manufacturer will likely have more accurate screen size calculations than you can do with a ruler on their website.

This is an official developer guide on the Android website. Check out the content under "Device Compatibility", which includes multiple articles on screen sizes.

\$\endgroup\$

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.