Wierd child

Hello,

So basicly I want to access a child from the parent.
So I’m doing it like I always does, transform.Find(“ChildName”);
Right now I want to access a child called “Platform” and I want the parent (Street) to access it.
So in a script on Street I write transform.Find(“Platform”); and I find a match. However, this match is not the child I want. This match is another Platform, even though Street only got 1 child called Platform.

So I loop through all my children in Street to see which children I have. The result is two Platforms, even though the Hierarchy view only says one.

I attach an image to show whats up.
As you can see, the hierarchy view (the upper one) only got one Platform, but in the output log, I get two Platform, one with 0 children and one with 3.

What is causing this?

transform.Find(“”) is correlating to transform.gameObject.Find(“”), this correlates to GameObject.Find(“”) which is a global search.

I suggest creating a local Find…

funciton FindChild( name : String){

var objs : Component[];
objs = gameObject.GetComponentsInChildren(Transform);
for (var obj : Component in objs) {
if(obj.name == name) return obj;
}
return null;

}

Thanks for your reply Big,

Since I got a weird copy of the child “Platform” a name search wont do me any good, I would get two hits on that if statement.
I decided to not waste more time into understanding what is causing this problem and just “haxx” my way out of it.

My solution will be to store all of the children in an array and pick no. 2 out of it, since it is always the child I want.