Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

NullReference error occuring when trying to access the index of an array from another script

$
0
0
To the awesome Unity Forums community, OVERVIEW: I have a list in a script: public class AlphaSpawner2 : MonoBehaviour public List Alpha2 = new List(); and this list when started has the values of the alphabet void Start() { for (char letter = 'A'; letter <= 'Z'; letter++) { Alpha2.Add(letter.ToString()); } } **ERROR:** Now basically these values are used to be displayed on text ui element. I want to be able to retrieve the value from the text (in another script) and be able to find the index of the element. public class Checker2 : MonoBehaviour { public void CountChecker() { Debug.Log("Checking..."); GameObject other = GameObject.Find("AOBDT"); AlphaSpawner2 alphaSpawner2 = other.GetComponent(); Text myText = gameObject.GetComponentInChildren(); char Indexfinder =char.Parse(myText.text); Debug.Log(Indexfinder); int CorrectNum2 = alphaSpawner2.Alpha2.IndexOf(Indexfinder.ToString()) + 1; // this line of code is where the error is at Debug.Log("Real Number:" + CorrectNum2); **Error displayed in console:** NullReferenceException: Object reference not set to an instance of an object Checker2.CountChecker () (at Assets/Scripts/CountingUp/Infinity/Checker2.cs:43) Checker2.OnMouseDown () (at Assets/Scripts/CountingUp/Infinity/Checker2.cs:30) UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32) Any help is greatly appreciated. Many huge thanks in advance for reading this.

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>