• 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 DayyanSisson · Mar 12, 2013 at 04:00 AM · rotationnullreferenceexceptionlocal

NullReferenceException (local rotation)

I'm getting this error: `NullReferenceException: UnityEngine.Transform.get_localRotation()` for this line right here:

 motor.axle.Rotate(Vector3.up * motor.RPM * Time.deltaTime);

The variable motor is this class:

 public class SimMotor {
 
     public bool active = true;
     public string ID = "MA-1";
     public float RPM = 1;
     public float torque = 1;
     public Transform motorBody = null;
     public Transform axle = null;
     public TextMesh systemDisplay = null;
     public SimGear engagedGear;
 
     public Material[] motorMaterials;
 }

So motor.axle is just the actual transform of the axle on the motor. I just want it to rotate but I keep getting that error. Any idea why?

Note: The 'axle' transform has no children.

Another note: It has nothing to do with the axle transform itself, because I get the error no matter what I set as the axle.

Another Another Note: I'm getting the feeling that Unity is weirding out because this only happened after the last update. Every single error I'm getting, I receive three times every frame and it treats it like they are all separate errors (even though I have Collapse on in the Debug log, there's three separate errors and they happen every frame). No idea why this is happening.

Comment
Add comment · Show 7
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 nsxdavid · Mar 12, 2013 at 04:50 AM 0
Share

If Unity is behaving strange.... try restarting it. Sometimes, this works. For realz.

Other than that, put in Debug.Log() messages directly before your motor.axel.Rotate() line that outputs everything.. motor, motor.axel, etc. to make sure the values are what you think they are.

avatar image DayyanSisson · Mar 12, 2013 at 05:00 AM 0
Share

Already restarted Unity. Already checked all the values, and they're all correct.

avatar image robertbu · Mar 12, 2013 at 05:24 AM 0
Share

The most likely problems is an uninitialized variable. Can you post the code where you create the 'motor' and initialize axel?

avatar image DayyanSisson · Mar 12, 2013 at 05:50 AM 0
Share

That might be it. I never initialize the variable, just assign it in the inspector. Although that should do it right?

avatar image robertbu · Mar 12, 2013 at 06:10 AM 0
Share

How do you assign it in the inspector? It's not derived from $$anonymous$$onobehaviour. You cannot just declare a variable of type "Sim$$anonymous$$otor" in the top of the script and use the inspector to initialize it.

Show more comments

1 Reply

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

Answer by 3dws · Mar 12, 2013 at 05:21 AM

hi . this error Occur when a variable was NULL ;

 public Transform axle = null;
Comment
Add comment · Show 2 · 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 DayyanSisson · Mar 12, 2013 at 05:49 AM 0
Share

If it was null, the error would say that it has not been assigned in the inspector, in which it has.

avatar image DayyanSisson · Mar 12, 2013 at 06:48 AM 0
Share

Check the last comment on the above comment thread. Feel like an idiot :D

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

How to open and close a door parented to a rotating object? 0 Answers

Hotween - local Rotation 1 Answer

Apply a Rotation in World Space based on Quaternions 2 Answers

mouse x not working when mouse y in use? 1 Answer

bone rotations changed in 4.3.2 inspector? 0 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