Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
-1
Question by jose94ji · Jan 19, 2013 at 07:00 PM · objectnull

NullReferenceException: Object reference not set to an instance of an object

HOw can i fix this error??

var walkAcceleration : float = 5; var cameraObject : GameObject; var maxWalkSpeed : float = 20; @HideInInspector var horizontalMovement : Vector2;

function Update () { horizontalMovement = Vector2( rigidbody.velocity.x, rigidbody.velocity.z); if (horizontalMovement.magnitude > maxWalkSpeed) { horizontalMovement = horizontalMovement.normalized; horizontalMovement *= maxWalkSpeed; } rigidbody.velocity.x = horizontalMovement.x; rigidbody.velocity.z = horizontalMovement.y;

transform.rotation = Quaternion.Euler(0,cameraObject.GetComponent(MouseLookScript).currentYRotation,0); rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") walkAcceleration, 0, Input.GetAxis("Vertical") walkAcceleration); }

Comment
Add comment · Show 5
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 Lovrenc · Jan 19, 2013 at 07:01 PM 0
Share

Firstyoushouldformatthecodeasthisisunreadable. Use

 101
 010


button.

avatar image Next Beat Games · Jan 19, 2013 at 07:18 PM 0
Share

I'm looking forward to when these forum API's will automatically format code.

avatar image andymads · Jan 19, 2013 at 08:43 PM 0
Share

Start by finding out which object is null.

avatar image robertbu · Jan 19, 2013 at 09:13 PM 0
Share

If you double click on the error in the console window it will bring up your code with the line the error is on highlighted. It will be a variable on that line that is initialized properly.

avatar image FL · Jan 19, 2013 at 10:02 PM 0
Share

Do you have a rigidbody component?

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by kru · Jan 20, 2013 at 02:53 AM

Either cameraObject is not set in the inspector, or the cameraObject that is being used doesn't have a MouseLookScript attached, or the object that this script is attached to doesn't have a rigidbody.

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 Chronos-L · Jan 20, 2013 at 02:59 AM 0
Share

:O I overlooked the $$anonymous$$ouseLookScript, I am not paying enough attention to the codes

avatar image
0

Answer by Chronos-L · Jan 20, 2013 at 02:01 AM

Either the gameobject this script is attached to do not have a rigidbody component or you forgot to set the var cameraObject : GameObject in your inspector.

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

15 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 avatar image avatar image

Related Questions

How can I get gameObject's all script components? 1 Answer

The Object you want to instantiate is null! 1 Answer

Null reference.. 2 Answers

AssetDatabase.CreateAsset() - Value cannot be null 2 Answers

Object reference not set to an instance of an object 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