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 chrisall76 · Aug 26, 2012 at 11:13 PM · guinullmatrix4x4

NullReferenceException using Matrix4x4?

I'm having a error with Matrix4x4, I use this code for automatic GUI position correction on different aspect changes:

 private var scale : Vector3;

 function OnGUI (){
     var scale : Vector3;
     scale.x = Screen.width/originalWidth; // calculate hor scale
     scale.y = Screen.height/originalHeight; // calculate vert scale
     scale.z = 1;
     var svMat = GUI.matrix; // save current matrix
     GUI.matrix = Matrix4x4.TRS(Vector3(0,0,0), Quaternion.identity, scale); // substitute matrix - only scale is altered from standard 
     
     var BulletsGUI = Bullets;
     var MagGUI = Clip;
     var BulletsW : String = "Ammo:";
     var BSlash : String = "/";
     
     GUI.skin = guiSkin;
     GUI.Label( Rect (25, 40, 800, 600), BulletsW.ToString());
     GUI.Label( Rect (85, 40, 800, 600), BulletsGUI.ToString());
     GUI.skin = guiSkinSmall;
     GUI.Label( Rect (100, 40, 800, 600), BSlash.ToString());
     GUI.Label( Rect (115, 40, 800, 600), MagGUI.ToString());
     //GUI.Label( Rect (x, y, ?, ?), name.ToString());
     GUI.matrix = svMat; // restore matrix
 }

But then I get this error: NullReferenceException: Object reference not set to an instance of an object UnityEngine.GUI.set_matrix(Stuff)

The error points here:

 GUI.matrix = Matrix4x4.TRS(Vector3(0,0,0), Quaternion.identity, scale); // substitute matrix - only scale is altered from standard 

Any help?

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
0
Best Answer

Answer by Eric5h5 · Aug 27, 2012 at 04:05 AM

You're probably using integer division with scale.x and scale.y, which is not what you want, since those are probably becoming 0, which isn't a valid number to use for the scale in this function. (Also, just so you know, you don't need to use ToString with variables that are already strings.)

Comment
Add comment · Show 3 · 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 chrisall76 · Sep 02, 2012 at 06:30 PM 0
Share

So how would I go about fixing that? $$anonymous$$inda stuck.

avatar image Eric5h5 · Sep 02, 2012 at 06:33 PM 0
Share

You mean the integer division? Just don't use integers for at least one of the variables involved in the division.

avatar image chrisall76 · Sep 02, 2012 at 06:49 PM 0
Share

I fixed it, a real stupid coding mistake by me. used OnGUI(); in my update functions, caused the error. Forgot to take all those out.

avatar image
0

Answer by DaveA · Aug 27, 2012 at 03:44 AM

try 'new'

Matrix4x4.TRS(new Vector3(0,0,0), Quater

or better yet

Matrix4x4.TRS(Vector3.zero, Quater

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 Eric5h5 · Aug 27, 2012 at 04:00 AM 0
Share

Unityscript doesn't need "new"; it's implicit. Even if it did, that's not the error message you'd get.

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

9 People are following this question.

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

Related Questions

How to Calculate BindPoses From My data? 2 Answers

Matrix 4x4 Error, MissingFieldExeption 1 Answer

Warning, null Texture passed to GUI.DrawTexture 0 Answers

Cannot apply certain elements in prefabs(GUI)? 1 Answer

GUI.Label font size scale - using GUISkin 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