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 CallMeFriend · Feb 20, 2014 at 10:46 PM · javascript

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

hello everyone

i am working on a pokemon game and i am basicly following on someone guide on youtube.. any way he gave this code

 var startPoint : Vector3;
 var endPoint : Vector3;
 var speed : float;
 private var increment:float;
 var isMoving : boolean;
 
 function Start () {
 
 startPoint = transform.position;
 endPoint = transform.position;
 
 }
 
 function Update () {
 
 if(increment <=1 && isMoving == true) {
 increment += speed/100;
 Debug.Log("Moving");
 }
 else {
 isMoving = false;
 Debug.Log("Stopped");
 }
 if(isMoving)
 transform.position = Vector3.Lerp(startPoint, endPoint, increment);
 
 
 if(Input.GetKey("w") && isMoving == false) {
 
 increment = 0;
 isMoving = true;
 startPoint = transform.position;
 endPoint = new Vector3(transform.position.x,transform.position.y,transform.postion.z + 20);
 }
 }
 
 
 
 
 
 
 
 
 
 

basicly when you run the game and prees the key W the player should move only he give me this code:

 NullReferenceException: Object reference not set to an instance of an object
 Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
 Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
 Boo.Lang.Runtime.RuntimeServices.GetProperty (System.Object target, System.String name)
 UnityScript.Lang.UnityRuntimeServices.GetProperty (System.Object target, System.String name)


anyone knows why?

thanks!

Comment
Add comment · Show 9
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 mattyman174 · Feb 20, 2014 at 10:50 PM 1
Share

Please use the 101010 Button to format your Code Correctly, makes it much easier to debug and read.

avatar image getyour411 · Feb 20, 2014 at 10:53 PM 1
Share

For this and future posts,

  1. Please format your code using 10101 button.

  2. Include the line# of the error

avatar image CallMeFriend · Feb 21, 2014 at 09:53 AM 0
Share

oh okay sorry i didnt know that is that better?

avatar image KiraSensei · Feb 21, 2014 at 09:57 AM 0
Share

You should tell us at what line is the error, you posted the error but not at what line it occured.

And in my opinion there is nothing in your posted code that can raise up this kind of error, so it may come from another block of code.

avatar image Linus · Feb 21, 2014 at 10:04 AM 0
Share

You replied with an answer and comment. But its ok Friend, it happens in most first questions.

$$anonymous$$nowing what line would help a lot. If you post the url to the tutorial Ill help compare the code to detect the error.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Wiki

Answer by Linus · Feb 21, 2014 at 11:16 AM

After more trial and error. The problem was a typo of transform.position.z on the last line.

When double clicking the error in Unity console I was taken to the line where the error was in monoDevelop.

Also make sure the speed is set in the inspector.

[ignore] After some trial of error, it was the Input.GetKey ("w") causing the problem. Its solved by using key code instead. [/ignore]

 var startPoint : Vector3;
 var endPoint : Vector3;
 var speed : float;
 private var increment:float;
 var isMoving : boolean;
 
 function Start () {
     startPoint = transform.position;
     endPoint = transform.position;
 
 }
 
 function Update () {
 
     if(increment <=1 && isMoving == true) {
         increment += speed/100;
         Debug.Log("Moving");
     } else {
         isMoving = false;
         Debug.Log("Stopped");
     }
 
     if(isMoving) transform.position = Vector3.Lerp(startPoint, endPoint, increment);
         
     if (Input.GetKey (KeyCode.W) && isMoving == false){
         increment = 0;
         isMoving = true;
         startPoint = transform.position;
         endPoint = new Vector3(transform.position.x,transform.position.y,transform.position.z + 20);
     }
     
 }


Comment
Add comment · Show 6 · 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 CallMeFriend · Feb 21, 2014 at 11:30 AM 0
Share

when i am adding { to the code this is the error i get:

 BCE0044: expecting }, found ''.

and if i use your code the game runs with no errors but the player still not moving.

any idea why?

avatar image Linus · Feb 21, 2014 at 11:32 AM 0
Share

Yeah I see it now, $$anonymous$$iss read it. Line 24 and 25 in your question code is suppose to be a one line statement. And not be its own if for the whole section. Dint notice because I stopped using them along time ago as i find it harder to read. Editing my answer

Updated code

avatar image CallMeFriend · Feb 21, 2014 at 11:59 AM 0
Share

still same error when pressing W /:

 NullReferenceException: Object reference not set to an instance of an object
 Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cache$$anonymous$$eyName, System.Type[] cache$$anonymous$$eyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
 Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cache$$anonymous$$eyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
 Boo.Lang.Runtime.RuntimeServices.GetProperty (System.Object target, System.String name)
 UnityScript.Lang.UnityRuntimeServices.GetProperty (System.Object target, System.String name)
avatar image Linus · Feb 21, 2014 at 12:22 PM 0
Share

You will not believe this, transform.postion.z is misspelled on the last line.

That was the whole problem it seems. I now tested it myself. This should be final

avatar image CallMeFriend · Feb 21, 2014 at 01:08 PM 0
Share

Works!... xd yepp it was spelled worng thanks for helping me! have a great day cya

Show more comments

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

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

Related Questions

Multiple Cars not working 1 Answer

Destroy GameObject A or B 1 Answer

Cube terrain with perlin noise 1 Answer

What is wrong with this script? 2 Answers

OnTriggerStay Not Working, JavaScript Help Needed 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