how do i find a transform’s child by it’s tag?
for example i have 8 transforms with the tag “u” but i want to find the one that is a child of a transform that i have as a variable
(i am using c#)
edit: i only have 3 children per parent so i can use a loop and check each child’s tag but i am sure that there is a better way…
So, in your example, you have 8 transforms and you want to find the one that is a child of another, known transform?
Why not simply loop through the 8 transforms, checking the “parent” property of each, until you find the one with the right parent?
Jeff
I think that’s a fine way of doing it as long as you aren’t doing it every frame but caching your results instead.
jgodfrey_1:
So, in your example, you have 8 transforms and you want to find the one that is a child of another, known transform?
Why not simply loop through the 8 transforms, checking the “parent” property of each, until you find the one with the right parent?
Jeff
i can do that but since i am going to do it 48 time every time the function is called i am looking for a better way of doing that…
and isn’t the way i suggested better then your’s since it only goes through the loop up to 3 times and yours can go through the loop 8 time?
I thought you had 8 transforms and you’re just looking for the one whose parent matches a known transform. I guess that’s not the case…
Jeff
as i told jeff I am going to call this 48 time about once per 5-10 seconds so i want to find a good way of doing it
no i have the opposite, i have 8 parents and each has 3 children and i am looking for the child that has a the tag i am looking for
How often do these relationships change? If not often, why not simply cache the results once you’ve figured it out the first time (as Garth suggested) and then reference the cache on successive searches. Then, just update the cache as necessary…
jgodfrey_1:
How often do these relationships change? If not often, why not simply cache the results once you’ve figured it out the first time (as Garth suggested) and then reference the cache on successive searches. Then, just update the cache as necessary…
the tags change every about 0.52 seconds but i don’t need to collect the data every time that they change…
edit: every times that i need to check this data it has been change almost completely so it will be a harder task to update it.
You could use transform.FindChild(GameObject.FindGameObjectWithTag(“u”).transform.name)
This seems like it will work, i will try it when i get back home
ok so i tried this but it returns NULL, the code i used was:
UnityEngine.Debug.Log(cubies[2].transform.FindChild(GameObject.FindGameObjectWithTag("u").transform.name));
cubies is an array of gameobjects and it has one child with the tag u