• 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
Question by vonbetelgeuse · Feb 08, 2017 at 06:09 PM · null reference exception

Null reference exception but working fine?

Reference is drag and dropped in the editor, Text name is spelled correctly, yet I get a Null Reference Exception w$$anonymous$$lst everyt$$anonymous$$ng functions fine. Did I potato somet$$anonymous$$ng?

Problem line is noted // PROBLEM HERE

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 
 public class menuButtons : MonoBehaviour {
 
     public bool english;
     public bool polish;
 
     public Text AboutButtonText;
     public Text WebsiteButtonText;
     public Text VirtualRealityButtonText;
     public Text AugmentedRealityButtonText;
     public Text AboutDescriptionTitleText;
     public Text AboutDescriptionText;
 
     public GameObject AboutDescription;
 
     // English Strings
     public string AboutButtonEN = "About";
     public string WebsiteButtonEN = "Website";
     public string VirtualRealityButtonEN = "Virtual Reality";
     public string AugmentedRealityButtonEN = "Augmented Reality";
     public string AboutDescriptionTitleEN = "About";
     public string AboutDescriptionEN = "About description here";
 
     // Polish Strings
     public string AboutButtonPL = "O nas";
     public string WebsiteButtonPL = "Strona internetowa";
     public string VirtualRealityButtonPL = "Wirtualna Rzeczywistosc";
     public string AugmentedRealityButtonPL = "Rozszerzona Rzeczywistosc";
     public string AboutDescriptionTitlePL = "O nas";
     public string AboutDescriptionPL = "Co robimy tutaj";
 
     void Start ()
     {
         AboutButtonText = GameObject.Find("AboutButtonText").GetComponent<Text>();
         WebsiteButtonText = GameObject.Find("WebsiteButtonText").GetComponent<Text>();
         VirtualRealityButtonText = GameObject.Find("VirtualRealityButtonText").GetComponent<Text>();
         AugmentedRealityButtonText = GameObject.Find("AugmentedRealityButtonText").GetComponent<Text>();
         AboutDescriptionTitleText = GameObject.Find("AboutDescriptionTitleText").GetComponent<Text>(); // PROBLEM HERE
         AboutDescriptionText = GameObject.Find("AboutDescriptionText").GetComponent<Text>();
 
         AboutDescription.SetActive(false);
         polish = false;
         english = true;
     }
 
     void Update ()
     {
         TextLanguage();
     }
 
     public void AboutButton()
     {
         AboutDescription.SetActive(true);
     }
 
     public void AboutDescriptionHide()
     {
         AboutDescription.SetActive(false);
     }
 
     public void WebsiteButton()
     {
         Application.OpenURL("http://unity3d.com/");
     }
 
     public void VirtualRealityButton()
     {
         SceneManager.LoadScene(2);
     }
 
     public void AugmentedRealityButton()
     {
         SceneManager.LoadScene(1);
     }
 
     public void EnglishButton()
     {
         polish = false;
         english = true;
     }
 
     public void PolishButton()
     {
         english = false;
         polish = true;
     }
 
     void TextLanguage()
     {
         if(english)
         {
             AboutButtonText.text = AboutButtonEN;
             WebsiteButtonText.text = WebsiteButtonEN;
             VirtualRealityButtonText.text = VirtualRealityButtonEN;
             AugmentedRealityButtonText.text = AugmentedRealityButtonEN;
             AboutDescriptionTitleText.text = AboutDescriptionTitleEN;
             AboutDescriptionText.text = AboutDescriptionEN;
         }
         else if(polish)
         {
             AboutButtonText.text = AboutButtonPL;
             WebsiteButtonText.text = WebsiteButtonPL;
             VirtualRealityButtonText.text = VirtualRealityButtonPL;
             AugmentedRealityButtonText.text = AugmentedRealityButtonPL;
             AboutDescriptionTitleText.text = AboutDescriptionTitlePL;
             AboutDescriptionText.text = AboutDescriptionPL;
         }
     }
 }
 
Comment

People who like this

0 Show 4
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 Paricus · Feb 08, 2017 at 06:31 PM 1
Share

try changing the name of the object and see if u still get the problem

avatar image vonbetelgeuse Paricus · Feb 08, 2017 at 06:51 PM 0
Share

Thanks for the suggestion but the same problem is still there :/

I'm thinking it might be a bug because the error only occurs once and everything works fine, none of the other texts on buttons throw up an error and everything is set up exactly the same.

Unless I have done something super potato...

avatar image Paricus vonbetelgeuse · Feb 08, 2017 at 07:03 PM 1
Share

if everything is working exactly how it should then it might be a bug, in which case you should report it. However I'd try copying the code onto a completely new script, remaking the buttons and restarting unity to make sure. If the problem is still there, its probably a genuine null reference and there's something you're missing.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by tormentoarmagedoom · Jun 27, 2022 at 06:58 PM

Hello! T$$anonymous$$s is a standard answer.

For Null Reference problems, you need to learn to find your problem by your own. As you can imagine, we can not try to read all scripts people posts, understand the logic and process, what all variables means, when or how you use them, and find where is the "problem". You are the only one who can do it...

Forst, check your error code, it says the line where the problem is. You need to debug the code w$$anonymous$$le running, and check the states of the variables of that line at the moment you see the problem, and I'm sure you will detect what variable is still NULL. Then investigate why.

Look for some tutorials on how to debug code w$$anonymous$$le running on your scripting software if don't know what I'm talking about.

Bye & good Luck!

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

92 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 avatar image

Related Questions

NullReferenceException: Object reference not set to an instance of an object 1 Answer

CAR ENTER EXIT 1 Answer

NullReferenceException: Object reference not set to an instance of an object 0 Answers

Null reference exception to a non-null text object? 1 Answer

Instantiate object through a coroutine problem 1 Answer


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