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 JackMac290400 · Feb 17, 2016 at 01:21 PM · error message

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

Hi, I'm relatively new to unity and I have just gotten the error NullReferenceException: Object reference not set to an instance of an object which I have managed to deal with in the past, but what I don't understand is that my script is working exactly as it should yet I am still getting this error. I have made this script to set three menus false whilst the user is playing my game and it starts fine and hides the menus from the user but I still get this error for some reason and I can't seem to find a solution The exact error is: NullReferenceException: Object reference not set to an instance of an object DeathMenuManager.NoMenus () (at Assets/Scripts/Managers/DeathMenuManager.cs:44) DeathMenuManager.Start () (at Assets/Scripts/Managers/DeathMenuManager.cs:22)

alt text

capture.png (42.9 kB)
Comment
Add comment · Show 5
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 Nerevar · Feb 17, 2016 at 01:40 PM 0
Share

Hello

I think in your function No$$anonymous$$enus() you should use the local reference Death$$anonymous$$enu, Respawn$$anonymous$$enu... ins$$anonymous$$d of using Find() again.

avatar image JackMac290400 Nerevar · Feb 17, 2016 at 02:05 PM 0
Share

I did that initially and got the same error

avatar image Nerevar JackMac290400 · Feb 17, 2016 at 02:17 PM 0
Share

Well that is weird you get the error on line 44 and not on line 19, do you have other scripts affecting those menus? because if the menus are inactive Find() is not going to work.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Falcon8857 · Feb 17, 2016 at 03:17 PM

Probably when starting the object there is no menu, but you are not using the reference there so DeathMenuManager.Start doesn't us the null pointer. But you call NoMenus in the same Start, and there you use the reference of the menu (wich hasn't been created yet) and that's why you get the null pointer reference error. If you do if (GameObject.Find("DeathMenu") == null) Debug.Log("No menu loaded!"); you will understand it better.

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 JackMac290400 · Feb 17, 2016 at 03:25 PM 0
Share

Thanks for the reply, I'm not to sure what you mean by the null pointer, like I said i'm still new to unity but I figured out why the error was occurring, I accidentally put the script in the scene twice so the start function was running twice and thus the void "No$$anonymous$$enus" was running twice causing the error

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

43 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 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

Keep getting Null reference error for AI Script 1 Answer

Unity 2017 playmode is not working 0 Answers

IndexOutOfRangeException in TextureInspector 1 Answer

Game scripts or other custom code contains OnMouse_ event handlers. Presence of such handlers might impact performance on handheld devices 2 Answers

grandle build fail 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