Work with GameObjects in a 3D Scene

Tutorial

·

foundational

·

+10XP

·

60 mins

·

(10591)

Unity Technologies

Work with GameObjects in a 3D Scene

In this tutorial, you’ll begin working in the Unity Editor with more independence than you experienced with the Microgames. You will start by creating a new Unity project and 3D Scene from scratch. Then, you will work with GameObjects and explore the various ways you can manipulate them in the Unity Editor. In this tutorial, you will:

  • Create a new 3D project and Scene.
  • Create new 3D GameObjects.
  • Select 3D objects in both the Hierarchy and Inspector windows of the Unity Editor.
  • Move, rotate, and scale 3D objects using numerical values using the Transform Component in the Inspector window.
  • Move, rotate, and scale 3D objects in the Scene view using the Unity transform tools.
  • Link GameObjects in parent-child relationships using the Hierarchy window to create complex GameObjects.
  • Identify the relationship between the properties displayed in the Inspector and the display of GameObjects in the Scene.

Languages available:

1. Overview

In this tutorial, you’ll apply what you have learned about the Unity Editor as you create and manipulate GameObjects in a scene. You’ll build more fundamental skills as you learn how to use the Hierarchy and Inspector windows to organize and configure your GameObjects.


2. Before you begin

Get familiar with the Editor controls


In this tutorial, you’ll begin using the techniques you learned in a Microgame and in the previous Unity Essentials mission. As we go through the next learning projects, we’ll presume that you can manipulate GameObjects and navigate in 3D space.


To review, see Explore the Unity Editor for basic techniques, tips, and tricks.


Try a Microgame


If you are new to Unity and you haven’t already taken the tutorials in one of the Microgames available in the Unity Hub, we highly recommend them — especially the LEGO® Microgame! Any of these Microgames will give you a good introduction to the Unity Editor.


Note: If you completed the LEGO® Microgame, you used some custom functionality that recreates the experience of using physical LEGO® bricks inside the Unity Editor. Here, you will not see the special LEGO® enhancements — you’ll be using the uncustomized Unity Editor.


Optional Step

3. Create a new 3D project and scene

Important: If you have already created a Unity project named “Essentials 3D project” in a previous mission, open that project from the Unity Hub and skip this step.


Follow these steps if you need to create a new Unity project for this tutorial:


1. Open the Unity Hub.


2. Create a new Unity project with the 3D template (using the Built-In Render Pipeline). Name this project “Essentials 3D project.”


Note: You might see a prompt to download the template if this is the first time you have used it. Look for this prompt on the template card when you select it.


3. If desired, create a new empty scene: from the main menu, select Assets > Create > Scene and give your new scene a name.


4. Create a cube primitive in your empty scene: right-click an empty section in the Hierarchy and select 3D Object > Cube.


4. The default 3D scene

In the Microgames, you started in a scene that was already built for you, with characters that moved and responded to your commands, a rigid ground on which they traveled, and goals and obstacles to make the game interesting. Now, however, you are working in a vast, boundless, empty space. A plane that looks like the ground is just for reference — it isn’t even a rigid surface.



The default 3D scene comes equipped with two important GameObjects, which are listed in the Hierarchy window:


  • Main Camera, which controls what your players will see in the Game view (Play mode).

  • Directional Light, which simulates the sun and provides light that will reflect off your 3D GameObjects to create realistic visual effects.

We will return to these after you have added more GameObjects to your scene.


5. Work with GameObjects in the Inspector

The Inspector window is where you will view and change the properties of GameObjects. To explore the properties of the Cube GameObject in the Inspector:


1. In the Scene view, create a cube primitive if you haven’t already (GameObjects > 3D Object > Cube), and from the Hierachy select the Cube GameObject you have created .


2. With Cube selected, look at the GameObject’s properties in the Inspector window.



Each section of the Inspector represents a component, which is a set of properties and behaviors of the selected GameObject. Some components are built-in to primitives like the ones you see here. Later, you will add more components to give GameObjects more sophisticated properties and behaviors.


With Cube selected, the Transform component displays the size, rotation, and position of the Cube GameObject in the scene using X, Y, and Z values. By default, these values are in meters.


Note: Unity uses a Y-up coordinate system. This means that in the Editor screen space, the y-axis is vertical and the x- and z-axes represent the horizontal plane (similar to north, south, east, and west). Some 3D applications, such as 3ds Max, use the z-axis as the vertical.


3. Select F on the keyboard to focus on Cube.


Tip: The Scene view window must be activated; you can select a GameObject in Scene view or hover over the Scene view window to activate the window.



The Move tool is selected by default, and its Gizmo is located in the center of the cube. The arrows point in the positive directions in each dimension. The dimensions are color coded. You can always get your bearings by looking at the scene gizmo in the upper-right corner of the Scene view.


4. With Cube selected, change the Y value of the Scale in the Transform component to 4. Zoom out as needed.



6. Organize GameObjects in the Hierarchy

You can use the Hierarchy window to organize your GameObjects and define their relationships to each other. You can group them in the Hierarchy to create more complex GameObjects.


1. In the Hierarchy window, right-click the Cube GameObject so that it is selected and a context menu appears.


2. Select 3D Object > Sphere.



As shown in the Hierarchy, Sphere is a child GameObject of Cube. These two objects are now linked. You can operate on them as a unit.



3. This sphere is inside the cube where you can’t see it. Select Sphere in the Hierarchy and the Gizmo will appear so that you can move it in the Scene view to a location at least partially visible outside of the Cube. It will be tall, not spherical, because its initial dimensions were based on its parent.



4. Select the parent object, Cube, and move it. Cube and Sphere will move together.


5. Try scaling and rotating the Cube, too. You’ll see that Sphere changes the same ways that Cube does. In fact, they are treated as one GameObject, as shown in the example below:



6. Select the Sphere GameObject and notice its coordinates in the Transform component. These are relative coordinates, which store the Sphere’s relationship to Cube — not Sphere’s position, rotation, and scale in the scene! Rotation values are 0, 0, 0, and Scale values are 1, 1, 1.



7. Try moving, scaling, and rotating Sphere and watch the Transform component values. You’ll see that Sphere moves independently, and the Transform component is recording its relative coordinates. Its transform values are only defined in relation to its parent.


8. To remove the parent-child relationship, drag Sphere in the Hierarchy up and all the way to the left to indicate the root level. Both GameObjects now appear as independent GameObjects in the Hierarchy, and Sphere’s Transform component displays coordinates in the scene space.



7. Next steps

You’ve seen how to add simple GameObjects, called primitives, to your scene, and you’ve seen the ways these GameObjects are represented in the Hierarchy and Inspector windows. You’ve seen how to move, rotate, and scale GameObjects in two ways: with numbers in the Inspector, or by physically changing them in the Scene view.


Now you’re ready for a practical exercise: building a structure using primitives.


Complete this tutorial