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 /
This question was closed May 25, 2014 at 09:09 PM by tanoshimi for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Le-Capitaine · May 25, 2014 at 08:42 PM · c#nullreferenceexceptionobject-reference-not-set

An object reference that seems pretty set-to-an-instance-of-an-object to me

Here's all of the relevant and semi-relevant code:

     public string[] options;
     public string[] optionNames;
     
     public List<GameObject> menus;
     GameObject[][] subMenus;
 
     GameObject[,] menuText;
     int menu = 0;
     
     int holdCounter;
     float oneFrameAgo;
     GameObject cursor;
     int[] selected;
 
     void Awake () {
         menuText = new GameObject[100,100];
         MakeSubmenuOf (options, optionNames, this.gameObject, 0, 20, 0.5f, 0.5f, 0.7f);
         cursor = new GameObject ("Pause Cursor");
         cursor.AddComponent<GUIText>();
         cursor.transform.parent = this.gameObject.transform;
         this.gameObject.SetActive (false);
     }
     
     void Update () {
         cursor.guiText.color = Color.red;

 //-----------------------
         cursor.transform.position = menuText[menu,selected[menu]].transform.position + Vector3.forward * 0.02f;
 //-----------------------

         cursor.guiText.text = menuText[menu,selected[menu]].guiText.text;
         cursor.guiText.alignment = menuText[menu,selected[menu]].guiText.alignment;
         cursor.guiText.anchor = menuText[menu,selected[menu]].guiText.anchor;
         cursor.guiText.font = menuText[menu,selected[menu]].guiText.font;
         cursor.guiText.fontSize = menuText[menu,selected[menu]].guiText.fontSize;
     }
 
     public void MakeSubmenuOf(string[] menuToMake, string[] niceNames, GameObject parent, int number,
                               int fontSize, float x, float y, float offsetBetween) {
         GameObject subMenuToMake = parent;
         for (int i = 0; i < menuToMake.Length; i++) {
             menuText[number,i] = new GameObject(menuToMake[i]);
             menuText[number,i].transform.position = new Vector3(x,y - (i * offsetBetween), 0);
             menuText[number,i].transform.parent = subMenuToMake.transform;
             menuText[number,i].AddComponent<GUIText>();
             
             menuText[number,i].guiText.text = niceNames[i];
             menuText[number,i].guiText.alignment = TextAlignment.Center;
             menuText[number,i].guiText.anchor = TextAnchor.MiddleCenter;
             menuText[number,i].guiText.fontSize = fontSize;
         }
         subMenus [number] = new GameObject[menuToMake.Length];
     }

I marked the line at which I get an NRE. I don't know what to think.

Comment
Add comment · Show 2
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 Jeff-Kesselman · May 25, 2014 at 08:50 PM 1
Share

There js LOT of dereferncing going on in that line check ALL of the following individually for non null values:

 cursor
 menuText 
 selected
 menu
 selected[menu]
 menuText[menu,selected[menu]]
avatar image Le-Capitaine · May 25, 2014 at 08:59 PM 0
Share

selected was it. Thanks again.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

21 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

Related Questions

NullReferenceException: Object reference not set to an instance of an object DestroyByContact.OnCollisionEnter2D (UnityEngine.Collision2D coll) 1 Answer

My Project doesn't work - Generic.List throws NullReferenceException ?! 0 Answers

Nested Class Initialization 1 Answer

Can't explain an NRE 0 Answers

Trouble with Null Reference in Script 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