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 KEELAN · Aug 30, 2014 at 01:00 PM · bugunassignedreferenceexcept

Weird UnassignedReferenceException bug

Hi, I found a very weird bug. If i do this

 void Update () {
         if(p2!=null)
         {
             Debug.Log("p2 exsists");
             Debug.Log(p2.transform.position);
         }
     }

then it runs and prints the position out

if i then drop the test and do this

  void Update () {
     Debug.Log(p2.transform.position);
         }

then it still prints out the position but it also puts out the UnassignedReferenceException error twice per frame.

Nothing else is changed and the gameobject p2 is a public variable and assigned in the inspector

Comment
Add comment · Show 3
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 _dns_ · Aug 30, 2014 at 01:29 PM 0
Share

Hi, strange, something must set it to null: did you try a "if (p2==null) then log something" ?

avatar image KEELAN · Aug 30, 2014 at 01:36 PM 0
Share

i did try that, that if statement returns true.

avatar image _dns_ · Aug 30, 2014 at 01:48 PM 1
Share

I guess you have multiple of those objects in your scene (the one containing the script with Update(), because there are 2 exceptions logged per frame). $$anonymous$$aybe one (two) of them doesn't have the p2 field set in the inspector ? Or maybe you instantiate one of those "object with this script" from a prefab that have the p2 field null ? Did you try log the this.name + this.gameObject.GetInstanceID() of the gameObject when (p2==null) ?

1 Reply

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

Answer by KEELAN · Aug 30, 2014 at 01:45 PM

Very sorry, i was making a dumb error. I duplicated the object with the script. So there were two objects with the script and only one had p2 assigned. Didnt see that. Again, apologies

regards

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 wanrclhnyd · Jan 09, 2020 at 10:52 PM 0
Share

thanks.. u helped me with "duplicate" clue

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

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

Related Questions

Editor Camera moving while rotating 0 Answers

My first time launching Unity and i have no text plz help 1 Answer

Object flips 90 degrees when I add a box Collider - strange 0 Answers

Changing Skybox tint in game, permanently changes it in editor? 1 Answer

Unity instantly crashes when switching from game to scene view. 2 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