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 DryTear · Apr 09, 2013 at 09:49 PM · error

Teleportation Problem

Heres the Script:

 var XPos : String = "X";
 var ZPos : String = "Z";
 var YPos : String = "Y";
 
 function Update(){
     transform.gameObject.position.x = XPos;
     transform.gameObject.position.z = ZPos;
     transform.gameObject.position.y = YPos;
 }
 
 function OnGUI(){
     XPos = GUI.TextField (Rect (2, 22, 100, 20), XPos, 3);
     ZPos = GUI.TextField (Rect (2, 44, 100, 20), ZPos, 3);
     YPos = GUI.TextField (Rect (2, 66, 100, 20), YPos, 3);
 
 }


And heres the error:

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.SetProperty (System.Object target, System.String name, System.Object value) Teleportation.Update () (at Assets/WorldBox/Scripts/Teleportation.js:6)

Line 6

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

1 Reply

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

Answer by whebert · Apr 09, 2013 at 10:08 PM

Not sure why you're getting a null reference exception, your code shouldn't really even compile. There is no position member of GameObject.

If you need to convert strings to floats, try this:

 var x : float = 0;
 var y : float = 0;
 var z : float = 0;
 
 float.TryParse(XPos, x);
 float.TryParse(YPos, y);
 float.TryParse(ZPos, z);
 
 transform.position = new Vector3(x,y,z);
Comment
Add comment · Show 7 · 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 Loius · Apr 09, 2013 at 10:46 PM 1
Share

it's a nullref because pragma strict was removed from the file, so js is being... "helpful" and assu$$anonymous$$g everything you type after a period is a legitimate member until runtime when it just gracelessly slams headfirst into nullref after nullref as it can't find these things /rant

it's generally a good idea to leave #pragma strict as the first line of the file.

avatar image whebert · Apr 09, 2013 at 10:54 PM 0
Share

Ah, cool. I usually code in C#, so hadn't run into that before. Thanks.

avatar image DryTear · Apr 10, 2013 at 12:23 AM 0
Share

ill try this tommorow, in meantime is there a way I can combine my code and your example. I need this for the multiplayer part.

avatar image whebert · Apr 10, 2013 at 12:30 AM 0
Share

Should just be:

 var XPos : String = "X";
 var ZPos : String = "Z";
 var YPos : String = "Y";
  
 function Update(){
     var x : float = 0;
     var y : float = 0;
     var z : float = 0;
  
     float.TryParse(XPos, x);
     float.TryParse(YPos, y);
     float.TryParse(ZPos, z);
  
     transform.position = new Vector3(x,y,z);
 }
  
 function OnGUI(){
     XPos = GUI.TextField (Rect (2, 22, 100, 20), XPos, 3);
     ZPos = GUI.TextField (Rect (2, 44, 100, 20), ZPos, 3);
     YPos = GUI.TextField (Rect (2, 66, 100, 20), YPos, 3);
  
 }
avatar image DryTear · Apr 10, 2013 at 02:05 AM 0
Share

Ohh Boy, cant wait to try this out tomorrow - Excited :]

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

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

Multiple Cars not working 1 Answer

Exception error 1 Answer

Error: error CS0029: Cannot implicitly convert type `UnityEngine.GameObject[]' to `UnityEngine.GameObject 1 Answer

Problem with camera in game mode. 0 Answers

Javascript GUI and deathscript weird compiler errors 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