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 /
avatar image
0
Question by dichterDichter · Feb 20, 2017 at 05:52 PM · nullreferenceexceptionnull reference exceptiontry-catch

Null Reference in Line 0

Can someone Help me finding this null reference? im getting this in my Debug in Visual Studio (HoloLens):

 NullReferenceException: Object reference not set to an instance of an object.
    at Degree.Update()
    at Degree.$Invoke7(Int64 instance, Int64* args)
    at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method) 
 (Filename: <Unknown> Line: 0)

i have 5 buttons and every button has this script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Degree : MonoBehaviour {
 
     public EV3Control legocontrol;
 
     public int degree;
 
     public Texture mouseover;
     public Texture option;
     public Texture selected;
 
     public GazeGestureManager Gazemanager;
     
     // Select Button
     void OnSelect()
     {
         legocontrol.DriveDegree(degree);
     }
 
 
     // Use this for initialization
     void Start () {
         Debug.Log(this.name);
     }
 
     // Update is called once per frame
     void Update () {
 
         int currentdegree = legocontrol.currentdegree;
         //Debug.Log("EV3: " + legocontrol);
 
 
         if (currentdegree == degree) {
             //Debug.Log("Active: " + this.name);
             try
             {
                 this.GetComponent<Renderer>().material.mainTexture = selected;
             }
             catch {
                 Debug.Log("catch active: " + this.name);
             }
         }
         if (currentdegree != degree)
         {
             if (Gazemanager.FocusedObject.name == this.name)
             {
                 //Debug.Log("Name: " + this.name);
                 try
                 {
                     this.GetComponent<Renderer>().material.mainTexture = mouseover;
                 }
                 catch {
                     Debug.Log("catch focus: " + this.name);
                 }
             }
             else {
                 //Debug.Log("Else: " + this.name);
                 try
                 {
                     this.GetComponent<Renderer>().material.mainTexture = option;
                 }
                 catch {
                     Debug.Log("catch no: " + this.name);
                 }
             }
         }
     }
 }

no catch is thrown. how yould i find the problem? or is the whole script in wrong place? There is no Problem in functionality, only errors in debugger.

Uncommenting everything and placing following scripf throws NullReference.

         Debug.Log("Gaze Name: " + Gazemanager.FocusedObject.name);
         Debug.Log("This Name: " + this.name);

this.name throws null?

UPDATE: oh, stupid: this is reference to script, not the GameObject its attached to.

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

· Add your reply
  • Sort: 
avatar image
0

Answer by gjf · Feb 20, 2017 at 05:51 PM

please try to format ALL code - it makes the line numbers from errors match up ;)

it's likely that legocontrol is null - you should add a Debug.Log() to see if that's the case... then only access currentdegree if it's not.

it's a good idea to the get the reference to the renderer/material in Awake()/Start() too... those operations are expensive.

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 dichterDichter · Feb 20, 2017 at 07:37 PM 0
Share

wow, how did that happen. i marked it as code.

avatar image dichterDichter · Feb 21, 2017 at 08:57 AM 0
Share

Hi, i checked legocontrol which seems never to be null. ins$$anonymous$$d i found that this.name and Gazemanager.FocusedObject.name is null when they are out of sight. im wondering about this.name very much.

         Debug.Log("Gaze Name: " + Gazemanager.FocusedObject.name);
         Debug.Log("This Name: " + this.name);

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Why am i getting a NullReferenceException when i switch platform to Android? 0 Answers

im getting this error: NullReferenceException: Object reference not set to an instance of an object Item.Start () (at Assets/Scripts/Inventory System/Item.js:9) 1 Answer

Object reference is NULL when IT IS set to an instance of an object? 1 Answer

Null Reference Exception Error. Modified Stats. Need Help. 1 Answer

NullReferenceException: Object reference not set to an instance of an object ProgressBar.Start () 2 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