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 cat.exe · Aug 14, 2013 at 11:51 PM · javascriptnullreferenceexception

Another Null Reference Exception

I am getting a null reference to the class partHull in the following code: (this is not all of it, only the important parts)

 public class partHull extends UnityEngine.MonoBehaviour
 {
     public var position            :int;
     public var isPartUsed         :boolean = false;
     private var jaska            :GameObject = Resources.Load("Alus");
     private var partLoc            :Vector3;
 
     public function partHull(num : int, vector : Vector3)
     {
         position = num;
         partLoc = vector;
     }
     public function guiLoop()
     {
         if (GUI.Button(Rect(10,170,50,30),"Plus")) {
             if (!isPartUsed) {
                 partHullInstance = Instantiate(jaska, partLoc, transform.rotation);
                 isPartUsed = true;
                 partHullInstance.AddComponent("FixedJoint");
                 partHullInstance.GetComponent("FixedJoint").connectedBody = rigidbody;
                 partHullInstance.GetComponent("FixedJoint").breakForce = 5;
                 partHullInstance.GetComponent("FixedJoint").breakTorque = 5;
             } else {
                 Destroy(partHullInstance);
                 isPartUsed = false;
 }    }    }    }
 
 paikka = new Vector3(-3,-3,0.75);
 var hull = gameObject.GetComponent(partHull);
 hull.partHull(1,paikka);
 
 function OnGUI () {
 hull.guiLoop();
 }

The line giving me problems is hull.guiLoop(); It should be noted that hull is successfully referenced once in hull.partHull(1,paikka);

I have no idea what is wrong, and I am new to js so help is appreciated.

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
0

Answer by DaveA · Aug 15, 2013 at 12:04 AM

Lines 28-30 are not in any function. 28 and 29 should be moved to line7, and 30 should be in some function.

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 cat.exe · Aug 15, 2013 at 01:02 AM 0
Share

I put 28 and 29 in start, because they initialize partHull hull.

I moved 30 to start also.

But now it tells me 'hull' is undefined.

Please tell me why it does not recognize my object

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

16 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

Related Questions

Multiple Cars not working 1 Answer

How to make a selection system? 1 Answer

How to spawn objects in a specific range of random location 1 Answer

My Object only moves when the variable ready is true. Problem is that ready is only ever true while update is running. So to move the object the variable always has to be true. How can I make it move if the variable ready is false. 1 Answer

Why is my code not working? 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