Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by blockhead · Feb 25, 2016 at 01:55 PM · c#bugnull reference exception

Unity Bug? null reference exception, Only its not null...

Hey, I have a slightly confusing issue..

Unity is throwing a Null Reference Exception at me:

 NullReferenceException: Object reference not set to an instance of an object
 Drag_Equipment.OnMouseDown () (at Assets/Scripts/Kitchen Scene/UI Scripts/Drag_Equipment.cs:285)
 UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)

When I go to that code line and check it out (Drag_Equipment.cs:285), its' throwing the error at the GameObject reference 'currentStation' on the GameObject 'equipment1'.

So, this seems like it should be pretty easy to solve, however when I pause the game and go in to the inspector I can see that 'currentStation' definitely has its value set...

And to further confuse me, 'currentStation' is pointing at separate GameObject called 'station1', now 'station1' is also pointing back at GameObject 'equipment1' on which the variable 'currentStation' exists in the script 'Drag_Equipment.cs'. And the confusion arises when I click on the reference on 'station1' pointing to 'equipment1' (where variable 'currentStation' is), it highlights the 'equipment1' in the Hierarchy as it should, and then when I unpause the game, the error is no longer being thrown, and things work as intended.

  • Quick edit/update here... Acutally I dont even have to click on 'station1's reference to 'equipment1', I simply have to click on the GameObject in which 'currentStation' is referencing, in the Hierarchy and then when I unpause, no more error, and it works as it should...

Any Ideas what might be causing this, or what I could do to fix it?

I've tried a couple things including resetting the value of 'currentStation' to what it should be, yet the error persists, until I pause, click it's reference in the inspector and unpause.. Its quite confusing..

Here is the bit of code which is throwing the error:

 void OnMouseDown(){
         
             // !!! if the recipe has finished cooking, and the player is trying to plate, instantiate the finishedRecipePrefab with artwork
             // and allow it to follow the cursor position based on the 'mouseDrag' script attached to it
 
             //Debug.Log ("mouse is down on " + this.gameObject.name + " on station " + GetComponent<Drag_Equipment> ().currentStation.name);
 
         //GetComponent<Rigidbody2D>().WakeUp();        // kick this thing so it realizes its on a station and can properly have its 'currentStation' set.
         Debug.Log("!!!!!!! Current station is" + currentStation.name);
         Debug.Log("!!!!!!! Finished cooking is" + finishedCooking);
         Debug.Log("!!!!!!! Current station recipe is " + currentStation.GetComponent<CookingStation> ().recipe);
         Debug.Log ("!!!!!!! Current staiton status is " + currentStation.GetComponent<CookingStation> ().stationStatus);
         if (currentStation != null) {
             if (finishedCooking && currentStation.GetComponent<CookingStation> ().recipe.recipePlated != true && currentStation.GetComponent<CookingStation> ().stationStatus == CookingStation.Station_Cooking_Status.Recipe) {

That very last if statement.. Somehow its getting past the first null check even. And also, all of the debug,log's I have above checking each part of the if statement are all able to be printed out to the console just fine, so its showing me that it has a value for everything in that if statement while still throwing the null reference exception...

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

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

MonoBehaviour Update called twice, fields being set to null 0 Answers

NullReferenceExeption mais variable initialisée 1 Answer

Disable array of components 1 Answer

help with a camera bug 0 Answers

[Forum bugged, can't delete] 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