Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by ina · Dec 21, 2012 at 01:08 PM · screendpi

Screen.dpi for in-editor

why does Screen.dpi return 0 for testing in editor

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Dave-Carlile · Dec 21, 2012 at 02:50 PM

According to the documentation, Screen.dpi may return 0 if Unity is unable to determine the value. I would imagine this is some sort of device or driver issue rather than Unity. It may only function on mobile devices, but that's just a guess.

Searching here for Screen.dpi I ran across this:

http://answers.unity3d.com/questions/337460/scaling-gui-buttons-to-be-the-right-size-no-mobile.html

They have a GetDPI function that looks like this

 private static float GetDPI()
 {
     return Screen.dpi == 0 ? DEFAULT_DPI : Screen.dpi;
 }

Where DEFAULT_DPI is set to 160.0. This looks like a reasonable approach to deal with the issue.

I may be way off base here, but in Windows at least I don't think there's any way to get an actual DPI for your monitor. Windows has a DPI setting that can be changed at will, but it doesn't reflect the actual DPI of the monitor unless you set it to that yourself. You could, however, probably implement a C# library to get that value if needed.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ina · Dec 23, 2012 at 01:29 AM 0
Share

yeah probably a better idea to have a helper function for dpi. nice use of ternary operators.

avatar image
1

Answer by xtyler · Jun 15, 2019 at 06:36 PM

With Unity's high DPI support (2018.2 I think?) we got this: EditorGUIUtility.pixelsPerPoint! It works beautifully across monitors of different resolutions and is consistent with the sizing of other Editor GUI elements. https://docs.unity3d.com/ScriptReference/EditorGUIUtility-pixelsPerPoint.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
-1

Answer by soxjke · Dec 21, 2012 at 02:56 PM

In play mode when free aspect is chosen for game view, dpi is exactly always 0. To get non-null dpi in editor specify target platform in build settings and display type in game view. But returned dpi will be your screen dpi. To debug actual dpi-dependent issues u have to debug on real deployment target(iOS device, Android device etc).

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ina · Dec 23, 2012 at 01:28 AM 0
Share

actually, even if you are in Android mode in editor, dpi will return 0

avatar image
-2

Answer by infinitypbr · Jan 24, 2013 at 01:24 AM

Retina mac returns 0 on game play, unfortunately :(

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is there a way to determine Android physical screen size? 5 Answers

Get Current Screen Window is Positioned In, Get Dpi of That Screen 1 Answer

How to obtain physical screen size in iOS simulator? 0 Answers

Detect physical resolution for showing SD or HD 0 Answers

Can I customize the resolution window that appears at the start of my executable? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges