• 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 Nick 21 · Feb 28, 2011 at 08:22 PM · nullreferenceexception

NullReferenceException FuelCellGlowLookAt.Update () (at Assets/Scripts/Misc/FuelCellGlowLookAt.js:7)

I'm getting this error, does anyone know how to fix it: NullReferenceException FuelCellGlowLookAt.Update () (at Assets/Scripts/Misc/FuelCellGlowLookAt.js:7)

This is the script:

// fuelCellGlowLookAt: Forces the object to always face the camera. // (Used for the 'glowing halo' effect behind the collectable items.)

function Update() { transform.LookAt(Camera.main.transform); }

function OnBecameVisible() { enabled = true; }

function OnBecameInvisible() { enabled = false;
}

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 Joshua · Feb 28, 2011 at 08:27 PM

Nullreference exception to my knowledge usually means you have a script attached to a gameObject, but there's something you haven't declared yet. For instance if you have var bulletPrefab : Transform; in your script so you can then attach a prefab to it later but you forget to do this, you'll get this error message.

When you click on this error in the compiler, look at your hierarchy screen. It should highlight the gameObject that is causing the error. See if you forgot to attach something here. If it's not that, all I can guess is that maybe you have deleted your main camera and are using a normal one? Because the script is referencing the main camera specifically.

Hope this helps, I'm a bit of a newb myself. :)

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 Nick 21 · Feb 28, 2011 at 08:34 PM 0
Share

Ok, thank you. It's because I deleted my main camera.

avatar image Joshua · Feb 28, 2011 at 08:35 PM 0
Share

That solves it then. Would you please check this answer as the correct answer to your question then? that'll stop the bot from bumping up a now useless thread.

avatar image
0
Best Answer

Answer by Bunny83 · Feb 28, 2011 at 08:36 PM

I guess you don't have a camera that is tagged as "MainCamera".

Camera.main returns the first Camera that is tagged MainCamera. If there is no cam, it will return null. You get this error because you try to access the transform of this null reference.

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.

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

1 Person is following this question.

avatar image

Related Questions

NullReferenceException help 1 Answer

NullReferenceException while trying to access script on object 2 Answers

instantiate prefab object to existing object 1 Answer

NullReferenceException in a GUI Dialog Method 1 Answer

Gameobject.find & my error NullReferenceException: Object reference not set to an instance of an object 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