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 $$anonymous$$ · Jun 18, 2015 at 06:23 AM · guiobjecttextnullreferenceexceptionobject reference

Object reference exists but also doesn't?

Note: I'm not sure if this is actually a GUI object issue or if it's an issue with objects in general. This is the first time I've seen anything like this and have no idea what to even think or do about it. If it's something unrelated to GUI specifically and has another reason for happening, please help me find out what's up.

I'm working on a party member display screen for an RPG I've been making. Things were going pretty smooth until I came to a jarring halt with this... whatever is happening.

alt text

A quick overview of how this works. The MenuParty script takes GUI text objects and assigns party information from a loaded CharacterData class. All the loading works perfectly fine. This shot shows that I've connected the references, and what the menu initially looks like before being overwritten with character data. Green lines are the ones that work fine. The red one however, inexplicably doesn't.

alt text

This shows a bulk of the information. Stats and icons and things are written perfectly fine without a complaint. The TextCharacterOverview object is treated no differently from TextCharacterStats or other text stuff at all. Yet for no reason I can see, it will not be actually found despite having its reference directly assigned to PanelCharacter, which has the script that writes the data to the Text objects. There's even a check to ensure that the reference textOverview isn't null. It even treats it as indeed existing, then immediately throws the NullReferenceException implying textOverview hasn't been linked. The else of that checker is to say "What the hell" if textOverview doesn't exist, but this code is never reached.

I've tried deleting that Text object and using a new one, rolled back my project to before I started doing this and reattempted to create and link the text (same thing occurs), and probably a couple other fix attempts that simply did not change it at all.

I can also mention that there isn't any other objects that are even capable of interfering with these menu things. Just a singleton where the CharacterData comes from (functions perfectly) and WorldManager that lets you return to the map you're currently on (functions perfectly). Neither do anything that can interfere with text or these objects directly. The full script to what goes on in the MenuParty.cs script is here, where all the manipulation occurs.

http://pastebin.com/w3B4iFw2 - using pastebin to not clog the post a bunch. I hope that's okay? DisplayStats() and DisplayOverview() are pretty similar, so the fact one works and the other just doesn't want to make me pretty sure there's something outside of just my code that is the problem.

I realize this isn't much to go by. What else could I be missing (it's probably staring me in the face)? Why does a reference exist then not exist when it must be written to? When is my hair going to turn grey? Thanks for reading through, and double so if you can help point me in the right direction. I'm having another instance of this occur in my project and they're going to be the death of me.

shot2.png (395.8 kB)
shot1.png (352.8 kB)
Comment
Add comment · Show 1
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 KayelGee · Jun 18, 2015 at 01:03 PM 1
Share

A shot in the dark but did you check if your CharacterData read is null?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Baste · Jun 18, 2015 at 02:37 PM

It's not the textOverview object that's null, it's the "read" object.

When you combine an assignment over several lines, the first line will show up as the one throwing the error, even if the nullreference is comming from a later line. Here's an example

 void Start() {
     string someText = "lol";
     string someOtherText = null;

     string testText = //the error will show up on this line
         "the first text has the length " + someText.Length +
         "\nthe second text has the length " + someOtherText.Length; //the error is caused here

     Debug.Log(testText);
 }

So either the read itself is null, or it's one of the indices of read.actions that is null. Hope that helps!

Comment
Add comment · Show 2 · 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 Baste · Jun 18, 2015 at 02:39 PM 0
Share

addendum: I'm pretty sure that this is because the compiler turns multiline assignments like that into one line, which means that the runtime can't know which of the lines that's causing the error.

avatar image $$anonymous$$ · Jun 18, 2015 at 04:14 PM 0
Share

This helped a lot, yeah. I mistakingly assumed that the actions would simply return null and Unity would perform black magic to just make it not add anything to the full string. Turned out that actions being null were the problem. I'll have to add a handle for it after all.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Problem with Null Reference Exeption??:/ 1 Answer

Making a script for all gameobject GUITEXT. 1 Answer

Why this Error when trying to add a score using the new GUI ? 0 Answers

NullReferenceException: Object reference not set to an instance of an object PlayerControl.Update () (at Assets/PlayerControl.cs:20) <-lineno:- 0 Answers

How to draw GUI Text from code 1 Answer


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