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
0
Question by Argenex · Dec 07, 2010 at 06:17 AM · guiresolutionguistyle

GUI.matrix - invalid matrix

Just trying to establish the basics of setting the GUI to adjust, however I can't even get GUI.matrix to work.

var customSkin : GUISkin; var nativeHorizontalResolution = 1920; var nativeVerticalResolution = 1080;

function OnGUI () { GUI.skin = customSkin; var Rwide = Screen.width; var Htall = Screen.height; Debug.Log("Resolution is:" + Rwide + "wide by" + Htall + "high"); //Out to console what our resolution is. GUI.matrix = Matrix4x4.TRS(Vector3(0,0,0), Quaternion.identity, Vector3(Screen.width / nativeHorizontalResolution, Screen.height / nativeVerticalResolution, 1)); }

I am trying this based on what is in the 3D Platformer Tutorial, but all I get is the following error:

Ignoring invalid matrix assigned to GUI.matrix - the matrix needs to be invertible. Did you scale by 0 on Z-axis?

I understand TRS (trans/rot/scale) and how it operates. What I don't understand is why it believes I am going negative (hence why I shoot out to log to see my Res to make sure), or that I am scaling in Z, as I am certainly not scaling Z. As for being invertible, well why does this code work other places and not here?

In the tutorial they even have it dividing against 1200 twice; which doesnt work and I had hoped the error in there was the reason:

GUI.matrix = Matrix4x4.TRS (Vector3( 0, 0, 0 ), Quaternion.identity, Vector3 (Screen. height / nativeVerticalResolution , Screen.height / nativeVerticalResolution , 1));

Any light shed upon why I am generating this error would be great, Thanks.

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

2 Replies

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

Answer by Eric5h5 · Dec 07, 2010 at 06:37 AM

"Screen.width / nativeHorizontalResolution" will not give you the result you want, as long as both of those are integers. You need at least one to be a float in order to get a float as a result instead of an integer. JS doesn't have an inline way to cast integers to floats, so you can use parseFloat or just add 0.0..."(Screen.width + 0.0) / nativeHorizontalResolution". Even though it also works to make nativeHorizontalResolution a float, I would recommend not doing that, since the resolution is inherently an integer, and it could potentially cause problems elsewhere.

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 clunk47 · May 28, 2013 at 06:23 PM 0
Share

Thank you.

avatar image
0

Answer by Argenex · Dec 07, 2010 at 06:24 AM

And the answer is....

var nativeHorizontalResolution = 1920.0;
var nativeVerticalResolution = 1080.0;

Guess it wants it to be float. Which is odd that it works within the 3D Platformer Tutorial, and works using screen.height twice..

Doing this removed the error.

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

2 People are following this question.

avatar image avatar image

Related Questions

How to Vertically Stretch a Custom Thumb for Unity Scrollbars 0 Answers

Is that a resolution-related issue? 1 Answer

Screen Resolution and GUI cutoff issue. Android. 1 Answer

Sometimes the GUI selectively doesn't render some letters 1 Answer

Resolution & aspect ratio GUI 1 Answer


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