I know what a nullReferenceException is typically an error for, but in the current issue I am having I cant seem to figure it out. I am wanting to save numerous objects, and their sprite renderers into arrays. But seem to be having an issue with the spriteRenderer part
GameObject[] currentReferencedGameobject;
SpriteRenderer[] spriteRenderer;
void Start()
{
currentReferencedGameobject = GameObject.FindGameObjectsWithTag("colourable");
for(int i = 0; i < currentReferencedGameobject.Length; i++)
{
Debug.Log(currentReferencedGameobject[i].name);
spriteRenderer[i] = currentReferencedGameobject[i].GetComponent<SpriteRenderer>();
}
}
The null ref error that I am getting in relating to the line spriteRenderer[i] = currentReferencedGameobject[i].GetComponent<SpriteRenderer>(); But I dont understand why. Each gameobject has a sprite renderer. And if i try it with just one of the objects (rather than the array) it works. Its only when I try to use the array i get the null ref error