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 /
avatar image
1
Question by TheGalacticShaman · Feb 15, 2019 at 08:50 AM · scripting problemui imageunassignedreferenceexcept

Unassigned reference exception on an assigned variable ?

Currently in my game, I have a mainMenu_UI object that contains a main menu script, and controls the menu. Usually, pressing "start game" works fine, however, in my main menu I have an options button, making the main menu.setactive = false, and the options menu.setactive = true. When I press back to return to the main menu, everything seems normal until i press "new game". At this point, the main menu is meant to be de-activated (the ui manager is inside of a "dontDestroyOnLoad", so it persists into the new scene). Unity does not deactivate the menu, and rather throws an error of "unassigned reference exception", referring to my mainMenu_UI object reference in my mainMenu script. Looking in the inspector, I can see that this variable is indeed assigned, and i am assigning it through the inspector at runtime. I dont know what to do as it is point to the problem but i just dont see what is wrong. There is no problem clicking straight onto new game, it seems to only hap-pen after the menu is de-activated then re-activated.Any help would be 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

4 Replies

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

Answer by TheGalacticShaman · Feb 15, 2019 at 09:45 AM

Just fixed the issue, if any one else is experiencing this, double check to make sure that you haven't applied the script to another object accidentally. I must have dragged it onto another game object without noticing, so there was a duplicate script that was missing the reference.

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 Royy212 · Jun 18, 2020 at 10:34 AM 1
Share

Bro, you've no idea how much you've just helped me, thank you!!!!

avatar image
1

Answer by tormentoarmagedoom · Feb 15, 2019 at 09:41 AM

Good day.

If you have a script with dontDestroyOnLoad, all its variables needs to be refeared by code, not via inspector... When scene changes, all objects are destroyed, so you need to refear them again, so must be the code itself who find and assign the variables again.

IF not, they will became null and this error appears.

Bye.

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 TheGalacticShaman · Feb 15, 2019 at 09:46 AM 0
Share

This was not the issue, as I was not trying to access a destroyed object. But thank you for taking the time to reply ! :)

avatar image
0

Answer by Zorkind · Apr 26, 2020 at 01:06 AM

Dude WTF how did i did that? D:

I just did what you did, somehow the script showed up on an object on another scene that i was not even working on :-(

Ghosts in here OwO

Comment
Add comment · 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
0

Answer by yengNami · Feb 16, 2021 at 03:33 AM

There are also instances where you detached the script/ or copy pasted component from one object to another. and transferred it to another game object, then you forgot to delete old script attached the old game object. so double check it first.

Comment
Add comment · 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

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

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

Related Questions

How to create HitCross on my gun`s sight when it hits the enemy. 1 Answer

OnPointerClick in child's script is not triggered when there exists a OnPointerDown in parent's script 2 Answers

Access a specific element in GridLayoutGroup by script ? 1 Answer

Resource load default unity sprite? 1 Answer

CaptureScreenshot superSize with UI 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