Transform
The Transform Component determines the actual Position, Rotation, and Scale of all objects in the scene. Every object has a Transform.
The Transform Component is viewable and editable in the Inspector
Properties
Position | Position of the Transform in X, Y, and Z coordinates. |
Rotation | Rotation of the Transform around the X, Y, and Z axes, measured in degrees. |
Scale | Scale of the Transform along X, Y, and Z axes. Value "1" is the original size (size at which the object was imported). |
All properties of a Transform are measured relative to the Transform's parent. If the Transform has no parent, the properties are measured relative to World Space.
Using Transforms
Transforms are always manipulated in 3D space using X, Y, and Z axes. In Unity, these axes are represented by the colors red, green, and blue respectively. Remember: XYZ = RGB.
Color-coded relationship between 3 axes and Transform properties
Transform Components can be directly manipulated using the Scene View or the Inspector. The Inspector will list the properties stated above for easy editing. You can also modify Transforms in your Scene by interacting with them, using the Move, Rotate, and Scale tools. These tools are located in the upper left-hand corner of the Unity Editor.
The View, Translate, Rotate, and Scale tools
The tools will be usable on any object in your scene. Click on the object, and you will see the tool gizmo appear around it. Depending on the current tool, the gizmo will look slightly different. Clicking the object will also cause the Transform component to become visible in the Inspector. If the Inspector does not display the Transform component or its properties, then you do not have an object highlighted in the Scene View.
All three Gizmos can be directly edited in Scene View.
To manipulate the Transform, click and drag on one of the 3 gizmo axes, you'll notice its color changes. As you drag the mouse, you will see the object translate, rotate, or scale along the axis. When you release the mouse button, you'll notice that the axis remains selected. You can click the middle mouse button and drag the mouse to manipulate the Transform along the selected axis. To access all 3 axes at once click and drag the center point of all 3 gizmos.
Any individual axis will become selected when you click on it
Parenting
Parenting is one of the most important concepts to understand when using Unity. When a GameObject is a Parent of another GameObject, the Child GameObject will move, rotate, and scale exactly as its Parent does. Just like your arms are attached to your body, when you turn your body, your arms move because they're attached. Any object can have multiple children, but only one parent.
You can create a Parent by dragging any GameObject in the Hierarchy View onto another. This will create a Parent-Child relationship between the two GameObjects.
A real-world example of a Parent-Child hierarchy. All the GameObjects with arrows to the left are Parents.
In the above example, we say that the arms are parented to the body, and the hands are parented to the arms. The scenes you make in Unity will contain collections of these Transform hierarchies. The topmost parent object is called the Root object. When you move, scale, or rotate a parent, all the changes in its Transform are applied to its children as well.
It is worth pointing out that the Transform values in the Inspector of any Child GameObject are displayed relative to the Parent's Transform values. These are also called the Local Coordinates. Through scripting, you can access the Global Coordinates as well as the Local Coordinates.
You can build compound objects by parenting multiple separate objects together, like the skeletal structure of a human ragdoll. You can also create small yet effective objects with single parents. For example, if you have a horror game that takes place at night, you can create an effective atmosphere with a flashlight. To create this object, you would parent a spotlight Transform to the flashlight Transform. Then, any alteration of the flashlight Transform will affect the spotlight, creating a convincing flashlight effect.
Importance of Scale
The scale of the Transform determines the difference between the size of your mesh in your modeling application, and the size of your mesh in Unity. The mesh's size in Unity (and therefore the Transform's scale) is very important, especially during physics simulation. There are 3 factors that can determine the Scale of your object:
- The size of your mesh in your 3D modeling application.
- The Mesh Scale Factor setting in the object's Import Settings.
- The Scale values of your Transform Component.
Ideally, you should not adjust the Scale of your object in the Transform Component. The best option is to create your models at real-life scale, so you won't have to change your Transform's scale. The second-best option is to adjust the scale at which your mesh is imported in the Import Settings for your individual mesh. Certain optimizations occur based on the import size, and instantiating an object that has an adjusted scale value can decrease performance. For more information, read through the Rigidbody component's section on optimizing scale.
Hints
- When parenting Transforms, put the parent's location at 0,0,0 before applying the child. This will save you many headaches later.
- Particle Systems are not affected by the Transforms Scale. In order to scale a Particle System, you need to modify the properties in the System's Particle Emitter, Animator and Renderer.
- If you are using Rigidbodies for physics simulation, there is some important information about the Scale property to be read on the Rigidbody page.
- You can change the colors of the Transform axes (and other UI elements) from the .
- If you can avoid scaling, do so. Try to have the scales of your object finalized in your 3D modeling application, or in the Import Settings of your mesh.