• 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 /
This question was closed Sep 07, 2017 at 09:10 AM by AitorLT for the following reason:

Fixed ^^

avatar image
0
Question by AitorLT · Sep 06, 2017 at 07:48 PM · errorerror messageerror-messageerrormessageerror reporting

I have an error "MissingReferenceException" and i dont know why

So..i creating an score and i works, when i kill the enemy it adds +10 to the score,when i get hit it quits 5 points to it, so everything works properly but i have this error all the time,i know my score works properly always but i dont understand why it appears. (Im new,maybe its just a silly error but i really dont know)

Error:

MissingReferenceException: The object of type 'Text' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. UnityEngine.EventSystems.UIBehaviour.IsActive () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/UIBehaviour.cs:22) UnityEngine.UI.Graphic.SetVerticesDirty () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Graphic.cs:100) UnityEngine.UI.Text.set_text (System.String value) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Text.cs:138) PlayerController.SetScore () (at Assets/PlayerController.cs:133) PlayerController.OnBecameInvisible () (at Assets/PlayerController.cs:99)

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

1 Reply

  • Sort: 
avatar image
1

Answer by Akusan · Sep 06, 2017 at 07:53 PM

You need to add a check on your script if enemy exists or not before accessing it's text variable. What happens is that you destroyed the enemy game object but you have some functions trying to access that destroyed game object's variables.

Comment
Add comment · Show 4 · 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 AitorLT · Sep 07, 2017 at 07:29 AM 0
Share

Oh i see, but how do i check it?

avatar image Akusan · Sep 07, 2017 at 09:50 AM 0
Share

Check if null, and if it is null, either add a return statement or create a target for your script. Here's an example using if null:

 private static Level$$anonymous$$anager instance = null;

 public static Level$$anonymous$$anager GetInstance(){
     if (instance == null) {
         instance = new Level$$anonymous$$anager ();
         instance.coloredList = new List<Color> ();
         instance.coloredList.Add (Color.red);
         instance.coloredList.Add (Color.yellow);
         instance.coloredList.Add (Color.blue);
     }
avatar image AitorLT Akusan · Sep 07, 2017 at 09:51 AM 1
Share

i already fixed it :D

avatar image Akusan AitorLT · Sep 07, 2017 at 09:53 AM 0
Share

Good job! :-D

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

91 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

Related Questions

Assets\PlayerController.cs(29,29): error CS0200: Property or indexer 'Vector3.normalized' cannot be assigned to -- it is read only 1 Answer

Weird Error after Update 3 Answers

Monodevelop Fatal Error 0 Answers

Errors i can't understand. SetSystemInterested 1 Answer

InvalidOperationException: EnsureRunningOnMainThread can only be called from the main thread 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges