- Home /
Problem in finding objects with a particular tag
Okay, so I am working on a project for past few days now which is kind of a classic platformer with a player and some enemies. I was finding enemies in my scene using
FindGameObjectsByTag(EnemyTag);
Up until now everything was fine and dandy, but suddenly for some reason when I ran my game today it started returning me clones of my enemy game objects, even though I don't have them. I have just 2 enemies but its returning a length of 5. I tried using
Resources.FindGameObjectsOfType(...;
but to no avail. I tried searching on the net but found just a temporary solution: change the tag. Can someone tell me whats causing the problem and help me solve it?
Well, that's a very odd problem. Are you sure you don't have any enemy in the scene that's deactivated?
yes, no other enemies. just the 2. still i am getting clones
Run a test: debug the name for the objects you're getting and verify if they are the 5 different or if you're getting repeated objects. Perhaps you set the tag by mistake in other objects.
Search your code for "Instantiate"? They are either in your scene (perhaps as a child of another object), or you're instantiating them in your code.
Your answer
Follow this Question
Related Questions
GameObject.findGameObjectsWithTag returning empty? 1 Answer
How Expensive is Find function? 3 Answers
Find object from another scene 1 Answer
Cant Find.() Text component in Canvas 2 Answers
Find All FindObjectOfType() 1 Answer