FindGameObjectsWithTag problem

Hi folks,

I’m having a bit of a problem assigning tagged objects to an array and then hiding them. What I’ve currently got is;

var FstFloor : GameObject[];
FstFloor = GameObject.FindGameObjectsWithTag("firstfloor");

for (var i = 0; i < FstFloor.length; i++) {
			FstFloor[i].GetComponent(MeshRenderer).enabled = false;
		}

When the script runs, one of the tagged objects vanishes but none of the others. The error message comes up;

If anyone knows how to fix this I’d be thankful!

Cheers,

  • Jon

My JS is rusty but this looks ok to me. I think your problem is not in that snippet of code. Are the other object’s tags set correctly? Do they all have meshRenderers? etc.

Doh!!!

That was it exactly… Testing with cubes, I grouped to keep things in order and of course the group doesn’t have a meshrenderer…

Thanks for pointing it out, Paulygons :slight_smile: