Step 2: Creation of the Unity basic game
Prerequisites
Before starting this tutorial, please ensure:
- You have correctly installed Unity and the required modules: Installation Guide.
- You are familiar with the editor's layout: Unity Interface Basics.
A. Project Setup
1. Import the Template
To start the game creation process, first clone or download the Simple Unity Template.
- Unzip the archive.
- Open Unity Hub.
- Click the Add button and select the unzipped
Unity Templatefolder. Note: Make sure to import the Unity Template folder (located inside simple.toolchain-Unity-6) and not the simple.toolchain-Unity-6 folder itself.
- Once imported, click on the project name in the list to launch it.
B. Scene Configuration
Once the project is open, the first step is to create a specific scene for the simulation.
1. Create the Scene
We want to establish a "decision maker" view from the sky. We will use a specific template for this.
- Go to File > New Scene (or press
Ctrl+N/Cmd+N). - Select the "Main Scene - Sky View Player" template.
- Click Create.
- Save your scene immediately: go to File > Save As..., navigate to
Assets/Scenes/, give your scene a meaningful name (e.g.,Traffic-VR), and click Save. Saving toAssets/Scenes/ensures you can reopen it later via File > Open Scene.
2. Verification: Scene Loading
Sometimes, Unity may not load all references correctly upon scene creation.
How to detect a loading error: You might encounter one of the two following issues immediately after creating the scene:
- Console Error: A red error appears:
NullReferenceException: Object reference not set to an instance of an object.
- Missing References: If you select the Manager object in the Hierarchy, the Player and Ground fields in the Inspector show as "None" or empty.
To fix this issue:
- Go to the Console tab and click Clear.
- Open a different scene (e.g.,
Assets/Scenes/Code Examples/Limit Player Movement). - Re-open your newly created scene.
- The error should disappear, and the Manager references should now be correctly assigned.
3. Configuration: Middleware Connection
Once the scene is loaded correctly, you must verify the external connection settings.
- Select the Manager object in the Hierarchy.
- Locate the Connection Manager component in the Inspector.
- Crucial: Ensure that the Fixed Properties checkbox is enabled.
Fixed Properties tells the template to use the IP address and port values you set here, rather than prompting the player at the startup menu. It does not mean the WebPlatform needs to be running at this point — you will start it later.
If Fixed Properties is not checked, the connection to the WebPlatform will not function correctly.
4. Troubleshooting: Lighting Warning
You may see a yellow warning in the Console stating:
"Lighting data asset 'LightingData' is incompatible with the current Unity version..."
To fix this:
- Go to Window > Rendering > Lighting.
- In the Lighting window, click Generate Lighting.
- Wait for the process to finish, then Clear the Console.
C. Gameplay Configuration
1. Game Manager: Tag Configuration
Crucial Step: Tags sent by the model must be explicitly defined in Unity to avoid synchronization issues.
To define a new tag:
- Select any Game Object.
- In the Inspector, click the Tag dropdown > Add Tag...
- Click + and type the tag name.
For this tutorial, please add a new tag named "road" (case-sensitive).
2. SkyViewPlayer Configuration
We will use the SkyViewPlayer prefab. To improve navigation speed:
- In the Hierarchy, expand SkyViewPlayer.
- Select the child object named Locomotion.
- In the Inspector, update the script values:
- Move Vertical Speed:
20 - Move Horizontal Speed:
20 - Rotation Speed:
10
D. Testing the Model
You can run the simulation in two ways:
- VR Headset: Build and deploy to the device.
- Unity Editor (Play Mode): Runs directly on your computer.
Simulator Requirement To control the player movements within the Unity Editor (Play Mode), you must use a Simulator. Note that on some platforms (like macOS), you may need to manually set it up.
Please follow the instructions in the Running a Model Game guide to properly set up the simulator.
Next Step: Proceed to Step 3