- Home /
The question is answered, right answer was accepted
Getting all objects with a tag and inserting them into an array of gameobject
Hi! I am trying to get all the objects with the tag "Movable" from the scene and inserting them into an array of Gameobjects. i have looked over examples from documentation but it does not seem to be working. Here is my code:
public GameObject[] MovableObjects;
void Start()
{
MovableObjects = Gameobject.FindGameObjectsWithTag("Movable");
foreach(GameObject objects in MovableObjects)
{
Debug.Log(objects);
}
}
I do not see anything in the console so clearly MovableObjects is empty.What am i doing wrong?
did you dibug.log moveableobjects just to make sure it is null
i just added this if(objects == null){ Debug.Log("null");} and it is not showing null
ok so upon adding more debug.logs i see it does not even enter the foreach loop
also $$anonymous$$ovableObjects is not null and if i try to see what it contains it returns nothing
maybe the tag is movable not $$anonymous$$ovable or another typo mistake like that
Answer by HarshadK · Oct 16, 2014 at 01:41 PM
When you are performing your FindGameObjectsWithTag in your script are your movable objects active? If they are not active then they won't be found.
yeah i typed it corectly on mono but typed it wrong here. :D
i tryed that and just like here it does not even enter the loop
and my objects are instantiated at runtime and they also have corect tags on
Can you just post a screenshot of one of your $$anonymous$$ovable object. Just to see if anything is missing there.
Follow this Question
Related Questions
Assigning tag on runtime break loop in C# unity3D 4.3. 1 Answer
How to create an array of Game Objects with different tags. 1 Answer
List and store vector3 of game objects with tag 1 Answer
Array Question Length (C#) 8 Answers
Array problems 3 Answers