In the last article, we explored the subject of prototyping our projects with primitive game objects before adding assets. This time around, we’re learning some more Unity development by learning how to create game objects out of other game objects.
You might recall a few articles ago I explained a simple method for organizing your Unity scenes. This was done by making use of the game object parent-child relationship. There are other ways to make use of this Unity feature, however, and one other way is by making composite objects. That is, to make a game object that is composed of multiple objects but moves and acts as one object. Let’s take a look!
Creating a composite object
First we’ll need a base object. This can be any kind of object, but I recommend going with an empty object. I have noticed that when you use a primitive as the base object, it influences aspects of any children objects it has.
Once we have created the base object, we can then create “child” objects by right clicking on our base object in the Hierarchy window. Alternatively, we could drag existing game objects into the base object to add them.
What can we do with a composite object?
Once the composite object is created, we can make the collection of objects do virtually anything we can do with a single game object. For example, we can move them, destroy them, instantiate them, and more as a single unit. We can also manipulate the composite object through scripts by referencing the base object.
It’s a simple thing to do, but quite powerful. That wraps up this article; next time we will be diving into sprite animation in Unity. Until then, good luck and happy coding!