• 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 PredatorProductions · Nov 09, 2016 at 07:47 PM · error messagetext box

Keep getting this error on different Text boxes. Any help would be appreciated!

NullReferenceException: Object reference not set to an instance of an object textHolder+c__Iterator1.MoveNext () (at Assets/Script/textHolder.cs:27) UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) textHolder:Start() (at Assets/Script/textHolder.cs:19)

The code:

using UnityEngine; using System.Collections; using UnityEngine.UI;

public class textHolder : MonoBehaviour {

 public string talking;
 private TextManager TMan;

 public float speed = 0.1f;
 //public string fullText;
 //private string currentText = "";

 public string[] talkingLines;

 // Use this for initialization
 void Start () {
     TMan = FindObjectOfType <TextManager> ();
     StartCoroutine(ShowText());
 }

 IEnumerator ShowText(){
     for (int i = 0; i < talkingLines.Length; i++) {

         talking = talkingLines[i];

         this.GetComponent<Text> ().text = talking;

         yield return new WaitForSeconds (1);
     }
 }
 
 // Update is called once per framea
 void Update () {
     
 }

 void OnTriggerStay2D (Collider2D other)
 {
     
     if (other.gameObject.name == "Player")
     {    
         if (Input.GetKeyUp (KeyCode.Space)) 
         {
             //TMan.ShowBox (talking);

              if (!TMan.talkingActive)
             
             {
                 TMan.talkingLines = talkingLines;
                 TMan.currentLine = 0;
                 TMan.showTalking ();
             }
         }
     
     }
 }

}

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 aditya007 · Nov 10, 2016 at 04:55 AM 1
Share

I don't know which specific line of code the error is pointing to, but as you said, you're getting error on Text box. It could be the line this.GetComponent<Text> ().text = talking; and if it is, then the reason is you don't have Text component attached to your gameobject. Please double check that.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Brylos · Nov 10, 2016 at 07:21 AM

I believe it has something to do with scripts detecting certain components. Check that you dont have any deleted scripts on objects and or dont have a public game object or component that isnt assigned to a script. I'm not completely sure that is how to fix it, but I hope this helps.

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.

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

79 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

Related Questions

Assets/Standard Assets/Detonator/System/DetonatorBurstEmitter.cs(66,53): error CS0246: The type or namespace name `EllipsoidParticleEmitter' could not be found. Are you missing a using directive or an assembly reference? 1 Answer

getting error "Operator '<' cannot be used with a left hand side of type 'Object' and a right hand side of type 'float'." 0 Answers

All compiler errors have to be fixed before you can enter playmode! UnityEditor.SceneView:ShowCompileErrorNotification() but my script has 0 errors 1 Answer

Keep getting Null reference error for AI Script 1 Answer

Unity 2017 playmode is not working 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