How can I easily dynamically move a stack of gameobjects?

I'd like to move a stack of gameobjects - like a pile of bricks - intuitively and quickly in code. I've already got the pile of gameobjects in the world and would ideally like to transfer them around whilst staying piled together as they currently are.

I'm wondering if perhaps i could do the following

  • have a carrying empty gameobject
  • position carrying gameobject at the centre bottom of the pile in the world
  • add each gameobject brick as children to the gameobject
    • it's crucial that in doing this the gameobject will stay in exactly the same world position
    • yet i guess their actual positions that are now relative to the carrying game object will need to be altered into the correct space?
    • once all gameobjects are added i can then simply translate the carrying game object around to move the pile of objects
    • after placing where desired I can then move each of the gameobjects out of the carrying gameobject hierarchy and back into the world root (or another suitable gameobject hierarchy)
    • if any space transformations were needed putting them into the carrying gameobject then i guess they'll need to be reversed here
    • the carrying gameobject can be left till its services are required again

It all sounds relatively straight forward, i guess the crux is

  • can you dynamically create hierarchies of gameobjects at runtime?
  • are space transformations required when objects are moved into and out of new hierarchies?
  • what members and functions are required to accomplish this?

Cheers

you can do this easily. you just need to set the transform.parent of each block to your parent gameobject and then set it back to null. there is no need to space transformations. go ahead and use great easy to use powerful unity!