Your First Networked Game "Hello World"
This "Hello World" guide walks you through creating a project, installing the MLAPI package, and creating the basic components for your first networked game.
#
Create a new project in Unity- Open the Unity Hub.
- Click New.
- Select type ā3Dā
- Rename the project "Hello World".
- Select the location to save the project.
important
This tutorial requires an MLAPI-supported version of Unity (2019.4+).
#
Import MLAPI Package via URLSee the Install MLAPI guide to install the MLAPI package.
#
Create the Basic ComponentsRight click in the Hierarchy tab of the Main Unity Window.
Select Create Empty.
Rename the GameObject NetworkManager.
tip
We renamed the GameObject because:
- It makes it easier to refer to later.
- There is one and only one NetworkManager, this is the object that contains the
NetworkManager
component.
You have now created a new GameObject called NetworkManager.
Select NetworkManager.
Click Add Component in the Inspector Tab.
Select MLAPI from the list shown.
Select
NetworkManager
Component from the list displayed.Inside the
NetworkManager
component tab, locate theNetworkTransport
field.Click "Select Transport".
Select
UnetTransport
.Create 3D Object->Capsule (name it Player).
Add a
NetworkObject
component.Click the Assets folder.
Create a new Folder and call it Prefabs.
Make Player a prefab by dragging it to Prefabs folder you just created.
Delete Player from scene.
tip
We remove Player, because we will be using the network library to spawn the player. The library cannot track objects that start in the scene.
Add Player prefab to
NetworkPrefabs
list inside ofNetworkManager
.Select Default Player Prefab.
tip
When you select the Default Player Prefab , you are telling the library that when a client connect to the game, automatically spawn this prefab as the character for the connecting client. If you do not have the default selected for any prefab the game will crash on client connect.
note
You may see the following error reported
There is no NetworkPrefab Marked as a PlayerPrefab
. Once you have completed the above steps you can clear the error.Create a 3D Object->Plane, centered at (0,0,0).
Click Play.
Click Start Host under NetworkManager.
Congrats!
Congratulations you have created a networked game. It is not a very flashy game but it is a networked game nonetheless. For the next steps in your journey see Building on "Hello World"