4. Positioning objects in the scene

Overview

In this tutorial, you will import the tutorial assets and position the provided objects in the scene.

Objectives

  • Learn how to position objects in the scene
  • Learn how to use MRTK's Grid Object Collection feature

Importing the tutorial assets

Download and import the following Unity custom package:

After you have imported the tutorial assets your Project window should look similar to this:

Unity Hierarchy, Scene, and Project windows after importing the tutorial assets

Tip

For a reminder on how to import a Unity custom package, you can refer to the Importing the MRTK instructions.

Creating the parent object

In the Hierarchy window, right-click on an empty spot, and select Create Empty to add an empty object to your scene:

Unity Create Empty contextual popup menu

Tip

To display your Scene and Game window side by side as shown in the image above, drag the Game window to the right side of the Scene window. To learn more about customizing your workspace, you can refer to Unity's Customizing Your Workspace documentation.

Right-click on the newly created object, select Rename, and change the name to RoverExplorer:

Unity Rename contextual popup menu

With the RoverExplorer object still selected, in the Inspector window, configure the Transform component as follows:

  • Position: X = 0, Y = -0.6, Z = 2
  • Rotation: X = 0, Y = 0, Z = 0
  • Scale: X = 1, Y = 1, Z = 1

Unity with RoverExplorer object selected and positioned

Note

The camera represents the users head and is positioned at origin, X = 0, Y = 0, Z = 0. In general, 1 unit in Unity is roughly 1 meter in the physical world. However, there are exceptions to this, for example, when objects are children of scaled objects. In the scenario above, the RoverExplorer is positioned 2 meters in front of and 0.6 meters below the user's head.

Adding the tutorial prefabs

In the Project window, navigate to the Assets > MRTK.Tutorials.GettingStarted > Prefabs folder:

Unity Project window with Prefabs folder selected

Tip

A prefab is a pre-configured GameObject stored as a Unity Asset and can be reused throughout your project.

From the Project window, click-and-drag the Table prefab on to the RoverExplorer object to make it a child of the RoverExplorer object, then in the Inspector window, configure the Transform component as follows:

  • Position: X = 0, Y = -0.005, Z = 0
  • Rotation: X = 0, Y = 0, Z = 0
  • Scale: X = 1.2, Y = 0.01, Z = 1.2

Unity with newly added Table prefab selected and positioned

Tip

To display your scene as shown in the image above, use the Scene Gizmo, located in the top right corner of the Scene window, to adjust the viewing angle to be along the forward Z axis, double-click the MixedRealityPlayspace object to focus on the camera, and zoom in as needed.

From the Project window, click-and-drag the RoverAssembly prefab on to the RoverExplorer object to make it a child of the RoverExplorer object, then in the Inspector window, configure the Transform component as follows:

  • Position: X = -0.1, Y = 0, Z = 0
  • Rotation: X = 0, Y = -135, Z = 0
  • Scale: X = 1, Y = 1, Z = 1

Unity with newly added RoverAssembly prefab selected and positioned

Organizing objects in a collection

In the Hierarchy window, right-click on the RoverExplorer object and select Create Empty to add an empty object as a child of the RoverExplorer, name the object RoverParts, and configure the Transform component as follows:

  • Position: X = 0, Y = 0.06, Z = 0
  • Rotation: X = 0, Y = 90, Z = 0
  • Scale: X = 1, Y = 1, Z = 1

Unity with newly created RoverParts object selected and positioned

In the Hierarchy window, select all the RoverExplorer > RoverAssembly > RoverModel > Parts child objects, right-click on them and select Duplicate to create a copy of each of the parts:

Unity with all Parts selected and Duplicate contextual popup menu

Tip

To select multiple adjacent objects, press-and-hold the SHIFT key while using the mouse to select the first and last object.

With the newly duplicated Parts child objects still selected, click-and-drag them on to the RoverParts object to make them child objects of the RoverParts object:

Unity with newly duplicated parts as children of RoverParts object

To make it easier to work with your scene, in the Hierarchy window, click the eye icon to the left of the object to toggle the scene visibility for the RoverAssembly object off. This hides the object in the Scene window without changing its in-game visibility:

Unity with RoverAssembly scene visibility off

Tip

To learn more about the Scene Visibility controls and how you can use them to optimize your scene view and workflow, you can refer to Unity's Scene Visibility documentation.

In the Hierarchy window, clean up the RoverParts child objects' names by replacing the appended (1) with _Part:

Unity with duplicated parts name cleaned up

In the Hierarchy window, select the RoverParts object, then in the Inspector window, click the Add Component button, and search for and select GridObjectCollection to add the GridObjectCollection component to the RoverParts object:

Unity RoverParts object with Add Component Grid Object Collection in progress

Configure the GridObjectCollection component values as follows:

  • Sort Type: Alphabetic
  • Layout: Horizontal
  • Cell Width: 0.25
  • Distance from parent: 0.38

Unity with GridObjectCollection component configured

Then click the Update Collection button to update the position of the RoverParts child objects:

Unity with GridObjectCollection component applied

Congratulations

In this tutorial, you learned how to position objects in the scene relative to the user and use MRTK's Grid Object Collection feature to organize objects in a collection.

Next Tutorial: 5. Creating dynamic content using Solvers