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 Tyyy1997 · Jul 13, 2014 at 03:45 AM · c#nullreferenceexception3dtext

NullReferenceException After A Few Hours?

Alright, so I have this very annoying problem that keeps occurring after an hour or so. I have 3 3D Text Objects that are being changed via the Update() method, and everything works great until after a certain amount of time that causes this line right here:

     GetComponent<TextMesh>().text = "Fuel: " + playerScript.Fuel.ToString("f1") + "%";

And 2 others that are closely like it to return a NullReferenceException. I can't find a solution once it occurs, UNLESS I restart Unity, which is making absolutely no sense whatsoever. Anybody care to shine some light on the subject?

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 gjf · Jul 13, 2014 at 09:04 AM 0
Share

you could add some Debug.Log()'s into it to find out which part is causing it... the GetComponent() or playerScript could be null at some point.

also, any reason you're doing GetComponent() and not using some cached version of it?

EDIT: annoyingly chrome removed the < Text$$anonymous$$esh > that i add (without spaces)

avatar image Owen-Reynolds · Jul 13, 2014 at 04:32 PM 0
Share

gif: for anything that I use only once every few seconds (like updating based on pickups, which this might be) I prefer to embed the GetComponent. Overall runs about as fast; easier to read and verify; avoids errors where you remake the item and forgot to update the saved link.

OP: hmmm...if restarting Unity fixes it, but Stop then Play again doesn't, maybe you're changing a prefab somewhere (which I think breaks it in the editor until you restart.)

avatar image Tyyy1997 · Jul 14, 2014 at 06:17 PM 0
Share

@Owen Reynolds, I suppose it could have been that, as I was having some prefab conflictions, this occurred around 3-4 times before it seemed to have ceased, but I didn't keep any time on it or anything.. Since then we threw out a majority of the system and started doing it a different way. $$anonymous$$aybe it was a Unity bug, maybe it was me touching something without knowing and the issue co$$anonymous$$g up later. Hasn't happened since.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Lachee1 · Jul 13, 2014 at 10:04 AM

can't help too much without the rest of the code and error. For example I don't know what is updating playerScript.Fuel, or if playerScript is changing at all.

It does seem though that your playerScript variable changes to null, as its the only thing that can be null! So make sure that it isn't being set to something that is null.

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 Tyyy1997 · Jul 14, 2014 at 06:13 PM 0
Share

I don't think you're understanding my issue, nothing is always null, after an allotted amount of time I get these errors without touching anything related to it (to my knowledge at least). I understand the primary OOP concepts and what not, this is an issue with either me, or Unity breaking something in the editor that causes this until a restart takes place.

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

23 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

Related Questions

C# Need Help Finding Where Null Reference Exception Is 2 Answers

C# Another Null reference exception 1 Answer

C# Textfield Null Reference Exception 1 Answer

C# Null Reference Exception in Custom Function 1 Answer

Working Reference Still Throwing Null Reference Error 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