- Home /
Gameobject into another Gameobject
Hi everybody, i'm new to unity and i'm just trying some functions atm. There is a thing that i'm not able to understand also with guides, tutorials and docs: How can i insert Gameobjects "B", "C", "D", ... into a GameObject "A"? I mean something like the Flame GameObject provided with the standard assets. Flame is a gameobject with only Transform as component, and in the project hierarchy it appears to have 4 objects inside it, 3 of these contain components Transform and Particle Emitter and the fourth is a "Light" object with components Transform and Light. So 4 distinct gameobject into a parent gameobject. I'd like to create something similiar, so that i can encapsulate in a single gameobject more gameobjects. All this through the editor interface, is it possible? I tried to drag an object "A" over another "B", but the result is that the destination object just get a copy of "A" components.
Thank you
To child the object A to B, just drag A over B in the Hierarchy view: A will be moved "inside" B, meaning B is its parent.
When your object is ready, you can drag it to the Project view, what will create a prefab of it.
@aldonaletto: this is exactly what i neede, thank you! (i don't know how to vote your answer, a comment isn't votable right?)
Answer by DaveA · Feb 28, 2012 at 02:20 AM
You are confusing Components and GameObjects. GameObjects contain Components. Transform is a Component. So are those other things. Transforms can also contain other Transforms (hierarchical parenting).
You can create an 'empty' game object (it will have a Transform, they all do), then add Components (from the Component menu, or drag/drop).
If you have something built up and want lots of copies of that, create a Prefab, then drop your game object onto that Prefab (in the Project view) and it makes a Prefab you can then drop lots of into your scene/hierarchy view.
I know the difference, probably i explained bad my needings. Anyway what i meant is to have more gameobjects (may them be spheres, cubes...) into a parent gameobject (a gameobject with only Transform as Component) so that moving around the parent, all his gameobject children move with him staying in a fixed position of a relative subspace (the space inside the parent object). I got my answer reading the comment above by aldonaletto, i was tring to drag the gameobject in the project view, but i had to do that in the Hierarchy view insted. Thank you all!
Your answer
Follow this Question
Related Questions
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
How to structure code for squad selection and movement 0 Answers
Enable and object after disable 0 Answers
Script to Keep One GameObject from Being Destroyed 0 Answers
How do I stop an immediate collision with all objects from ocuring at the entry of game mode? 0 Answers