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

onClick.AddListener throwing "Object reference not set to an instance of an object" error

$
0
0
Hi, everyone! I'm a rookie programmer and I'm learning Unity. I have a problem in my script because it throws a "NullReferenceException: Object reference not set to an instance of an object" error but I can't see why this is. Here is the script section that is involved in the problem: GameObject slotFolder = canvas.transform.GetChild(20).gameObject; GameObject slotButtonsFolder = canvas.transform.GetChild(21).gameObject; int index = 0; for (int j = 0; j < 6; j++) { for (int i = 0; i < 7; i++) { GameObject goo = Instantiate(moduleSlotPrefab, new Vector3(460 + (i * 167.8f), 260 + (94.7f * j), -1), Quaternion.identity) as GameObject; goo.transform.parent = slotFolder.transform; string name = ""; name = name + j; name = name + i; goo.name = name; if (j == 0 || j == 1 || j == 4 || j == 5) goo.transform.GetChild(0).gameObject.SetActive(true); slots[index] = goo; if (index < 41) index++; } } index = 0; for (int j = 0; j < 6; j++) { for (int i = 0; i < 7; i++) { GameObject goo = Instantiate(slotButtonPrefab, new Vector3(600 + (i * 30), 50 + (20 * j), -1), Quaternion.identity) as GameObject; goo.transform.parent = slotButtonsFolder.transform; string name = ""; name = name + j; name = name + i; goo.name = name; buttons[index] = goo; Debug.Log(slots[index].GetComponent()); goo.GetComponent

Viewing all articles
Browse latest Browse all 2891

Trending Articles



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