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 Skyryk · Jan 07, 2018 at 10:08 PM · buginspector

Need help with a Null Reference Exception Error

I have run into a very weird Null Reference Exception Error. Pretty much whats going on is that I have a menu for a turn based battle system I'm working on, and am currently working on being able to go back if you selected the wrong move. This system works very well for me however it only work correctly if I have the inspector open and focused on the script that is being used to run all this. If the inspector in on a different object then what the script is attached too, or just isn't open at all I run into a Null Reference Exception. This just seems super bizarre to me and I'm still pretty new too unity so I have no idea what to do.

Also let me know if you need more information and I'll do my best to provide it.

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 Hellium · Jan 07, 2018 at 11:44 PM 0
Share

Can you copy-paste the full error given by your console?

avatar image Skyryk Hellium · Jan 08, 2018 at 04:05 AM 0
Share

Of course, here is the full error.


NullReferenceException: Object reference not set to an instance of an object Battle_Event.GoBack () (at Assets/Scripts/Battle_Event.cs:589) Battle_Event.Update () (at Assets/Scripts/Battle_Event.cs:245)
Additionally here is the code that it is referring to, line 589 is the first if statement. After a bit more missing around I noticed that this only happens if I'm trying to make the 3rd if statement be true. It also doesn't matter what order the if statements are arranged in, it will only return the error if the first 2 are suppose to be false.

 case BattleSequence.selectingPlayer:
                 if (playerTurnStorage[PTSNum].selectedSkill.defence > 0)
                 {
                     //Gets rid of the PTS
                     playerTurnStorage.Remove(playerTurnStorage[PTSNum]);
 
                     currentSequence = BattleSequence.selecting$$anonymous$$ove;
 
                     //Sets the correct cursor to be active
                     UI_Cursor.S.gCursor.SetActive(true);
                     UI_Cursor_1.S.gCursor.SetActive(false);
                     break;
                 }
 
                 if (playerTurnStorage[PTSNum].selectedSkill.name != null && playerTurnStorage[PTSNum].selectedSkill.defence == 0)
                 {
                     //Gets rid of the PTS
                     playerTurnStorage.Remove(playerTurnStorage[PTSNum]);
 
                     //$$anonymous$$akes the Skills slide back down
                     Battle_Skill_$$anonymous$$enu.S.slideDownSkills = true;
 
                     currentSequence = BattleSequence.selectingSkill;
 
                     //Sets the correct cursor to be active
                     UI_Cursor.S.gCursor.SetActive(true);
                     UI_Cursor_1.S.gCursor.SetActive(false);
                     break;
                 }
 
                 if (playerTurnStorage[PTSNum].selectedItem.name != null)
                 {
                     //Gets rid of the PTS
                     playerTurnStorage.Remove(playerTurnStorage[PTSNum]);
 
                     //$$anonymous$$akes the Items slide back down
                     Battle_Item_$$anonymous$$enu.S.slideDownItems = true;
 
                     currentSequence = BattleSequence.selectingItem;
 
                     //Sets the cursor to be false
                     UI_Cursor_1.S.gCursor.SetActive(false);
                     break;
                 }
                 break;

avatar image Skyryk Skyryk · Jan 08, 2018 at 06:00 AM 0
Share

Alright well I manged to figure out a work around, however I'm still curious why the error showed up when I didn't have the Inspector pulled up. I mean why would that effect whether playerTurnStorage[PTSNum].selectedItem is null or not.

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

128 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

Related Questions

How do I fix broken inspector in unity? 1 Answer

Animator StateMachineBehaviour scripts are collapsed in inspector 0 Answers

Codeless IAP causing inspector bug 0 Answers

Inspector overlapping component problem 2 Answers

Inspector assigned variables not assigning in build 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