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 MDMLab · Apr 28, 2017 at 05:59 AM · nullreferenceexceptionscoreenabledbehaviour

random occuring NullReferenceException

I have the following problem: My game throws me follwing error at a random occuring basis. I have not found any pattern in it or anything. When I start the game and try to interact with an object sometimes the error pops up. If not the game runs smooth till the finish. I'm quite helpless with it. Has anyone an Idea?

 NullReferenceException
   at (wrapper managed-to-native) UnityEngine.Behaviour:get_isActiveAndEnabled ()
   at UnityEngine.EventSystems.UIBehaviour.IsActive () [0x00002] in C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\UIBehaviour.cs:22 
   at UnityEngine.UI.Graphic.SetVerticesDirty () [0x00002] in C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\UI\Core\Graphic.cs:100 
   at UnityEngine.UI.Text.set_text (System.String value) [0x00053] in C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\UI\Core\Text.cs:138 
   at Score.AddToScore1 (Int32 i, System.String name) [0x000ff] in D:\Unity\TauchroboterSpiel_25_04\Assets\Scripts\Score.cs:43 
   at Collectable.OnEndDrag (UnityEngine.EventSystems.PointerEventData eventData) [0x00188] in D:\Unity\TauchroboterSpiel_25_04\Assets\Scripts\Collectable.cs:166 
   at UnityEngine.EventSystems.ExecuteEvents.Execute (IEndDragHandler handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00008] in C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\ExecuteEvents.cs:80 
   at UnityEngine.EventSystems.ExecuteEvents.Execute[IEndDragHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) [0x00073] in C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\ExecuteEvents.cs:269 
 UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
 UnityEngine.DebugLogHandler:LogException(Exception, Object)
 UnityEngine.Logger:LogException(Exception, Object)
 UnityEngine.Debug:LogException(Exception)
 UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1) (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\ExecuteEvents.cs:273)
 UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean) (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:302)
 UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents() (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:200)
 UnityEngine.EventSystems.StandaloneInputModule:Process() (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:183)
 UnityEngine.EventSystems.EventSystem:Update() (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\EventSystem.cs:287)

Here the related part of the Code (it's a MonoBehaviour):

 public int score1 = 0;
 public int score2 = 0;
 public Text txtscore1, txtscore2;
 
 List<string> collected1 = new List<string>();
 List<string> collected2 = new List<string>();
 
 public OnScreenText onScreenText;

 void Start(){
     
     onScreenText = GameObject.Find("GlobalController").GetComponent<OnScreenText>();
 }
 
 void Awake() {
 DontDestroyOnLoad(transform.gameObject);

}

 public void AddToScore1(int i, string name){
     if(collected1.Count > 0){
         bool add = true;
         foreach(string s in collected1){
             if(s == name){
                 add = false;
             }
         }
         if(add){
             collected1.Add(name);
             score1 += i;
             txtscore1.text = "" + score1;
             onScreenText.DisplayText("+"+i,1f,1);
         }
     }else{
         collected1.Add(name);
         score1 += i;
         txtscore1.text = "" + score1;
         onScreenText.DisplayText("+"+i,1f,1);
     }
 }


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 aahinoam · Nov 23, 2017 at 01:33 PM 0
Share

@$$anonymous$$D$$anonymous$$Lab, did you succeed to solve it? If yes, can you share?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Kaasa_Abdul · Jan 19, 2018 at 05:10 PM

Perhaps you forgot to unsubscribe the handler when the object gets destroyed.

I wrote

 private void Awake() {
     Event += Handler;
 }

but forgot

 private void OnDestroy() {
     Event -= Handler;
 }

and thus had the same error.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Why isnt the enabled property part of an interface? 0 Answers

Scoring Points with UI Problem! 0 Answers

Score, FixedUpdate and Update 0 Answers

How do I make score appear when game is over and record high score? 2 Answers

How to make a score counter? 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