- Home /
How to set parents of all objects in an array?
Hello all,
I am trying to parent all the gameobjects in an array to a single parent. I have got all the objects in an array via
GameObject.FindGameObjectsWithTag
and now I want to change the parent of all of them. I tried doing this by getting the array
(var parts : GameObject [])
and then using parts.transform.parent == parentobject.transform.
I wasn't expecting this to work, but I did try it. I then set up a system where Unity loops, and parents the gameobjects together. This worked, but with the large number of objects in the array that needed parenting, this is taking 10-20 seconds. I need this to happen in a single frame. Does anyone have an idea on how to do this?
javascript only, please
thanks
Answer by Eric5h5 · Jan 31, 2014 at 12:27 AM
You need to iterate through the array and set the parent of every object. That's always how you do stuff to multiple objects, for anything. There's no way it should take anywhere remotely near 10-20 seconds, unless by "large number" you mean "really absurdly huge ridiculous number", in which case the only thing you can do is reduce the number of objects.
thanks eric, and I am talking about an absurdly huge number in this case :P
In that case having so many separate objects would be causing other problems, so you should rethink your approach.
Your answer
Follow this Question
Related Questions
How do to you save time for each player and display it? 2 Answers
getting "null" when using array. (javascript) 1 Answer
Distance error: Cannot cast from source type to destination 0 Answers
Having Multiple Controllable FPS Units Selected From A Singular RTS Mode? 0 Answers
2Dimensional Array? 1 Answer