You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* fixing typos and broken links
* clarifying the Testing Hello World section
* Clarified the usage of OnNetworkSpawn in HelloWorldPlayer
* clarified Adding Editor Modes section in GP1
* clarified use of command line helper
* Adding high-level explanation of what NetworkManager and UTP are in HelloWorld tutorial, with links to detailed docs
* restructured GP1 to have instructions to add script after description of why we add them
* adding links to gp_intro
Co-authored-by: Larah Armstrong <[email protected]>
| Creating a new project<br/> Installing Netcode<br/> Creating and testing the basic networking building blocks<br/> |Adding scripts to objects<br/> Editor modes (Host Server and Client)<br/> Basic player movement <br/>Basic RPC and Network variable use |
22
+
|[Creating a new project](../helloworld.md#create-a-new-project-in-unity)<br/> [Installing Netcode](../helloworld.md#install-netcode)<br/> [Creating and testing the basic networking building blocks](../helloworld.md#create-the-basic-components)<br/> |[Editor modes (Host Server and Client)](gp_module_one.md#adding-editor-modes-to-hello-world)<br/> [Basic player movement](gp_module_one.md#adding-basic-movement-to-the-player-object) <br/>[Basic RPC and Network variable use](gp_module_one.md#some-simple-rpc-use)|
In the HelloWorld project, you created a **NetworkManager** by adding the pre-created **NetworkManager** component. In Play Mode, the NetworkManager shows Editor buttons labeled `Start Host`, `Start Client`, and `Start Server` in its inspector. These call the `StartHost`, `StartClient` and `StartServer` methods of the **NetworkManager** respectively, to initiate a networking session. Inside the `HelloWorldManager.cs` script, we define two methods which mimic this functionality via UI buttons and status labels.
98
33
99
34
1. Create an empty `GameObject` rename it **HelloWorldManager**.
100
-
1. Create a script called `HelloWorldManager`.
101
-
1. Open the `HelloWorldManager.cs` script.
102
-
1. Edit the `HelloWorldManager.cs` script to match the following.
35
+
2. Open the **Scripts** Folder.
36
+
3. Create a script called `HelloWorldManager`.
37
+
4. Open the `HelloWorldManager.cs` script.
38
+
5. Edit the `HelloWorldManager.cs` script to match the following.
103
39
104
40
:::tip
105
41
You can copy the script from here and paste it into your file.
@@ -180,10 +116,6 @@ namespace HelloWorld
180
116
181
117
1. Add the `HelloWorldManager` script component to the `HelloWorldManager``GameObject`.
182
118
183
-
## Adding Editor Modes to Hello World
184
-
185
-
Inside the `HelloWorldManager.cs` script, we define two methods which mimic the editor buttons inside of **NetworkManager** during Play mode.
186
-
187
119
<detailsopen>
188
120
<summary>Click to show/hide the Code.
189
121
</summary>
@@ -208,7 +140,7 @@ Inside the `HelloWorldManager.cs` script, we define two methods which mimic the
208
140
```
209
141
</details>
210
142
211
-
`NetworkManager`implements the singleton pattern as it declares its singleton named `Singleton`. This is defined when the `MonoBehaviour` is enabled. This component also contains very useful properties, such as `IsClient`, `IsServer`, and `IsLocalClient`. The first two dictate the connection state we have currently established that you will use shortly.
143
+
You can statically access the `NetworkManager`instance from any other scripts via its singleton named `Singleton`. This is defined when the `MonoBehaviour` is enabled. This component also contains very useful properties, such as `IsClient`, `IsServer`, and `IsLocalClient`. The `IsClient` and `IsServer` properties dictate the connection state we have currently established that you will use shortly.
212
144
213
145
We call these methods inside of `OnGUI()`.
214
146
@@ -244,7 +176,67 @@ You will notice the introduction of a new method, `SubmitNewPosition()`. This is
244
176
245
177
## Adding basic movement to the Player object
246
178
247
-
The `HelloWorldPlayer.cs` script adds some basic movement to the Hello World player.
179
+
Here we will create a `HelloWorldPlayer.cs` script that adds some basic movement to the Hello World player.
180
+
181
+
1. Open the **Scripts** Folder.
182
+
1. Create a new script called `HelloWorldPlayer`.
183
+
1. Open the `HelloWorldPlayer.cs` script.
184
+
1. Edit the `HelloWorldPlayer.cs` script to match the following.
Any `MonoBehaviour` implementing `NetworkBehaviour` can override the Netcode method `OnNetworkSpawn()`. This method is fired when the `NetworkObject` gets spawned. We override `OnNetworkSpawn` since a client and a server will run different logic here.
310
-
311
-
:::note
312
-
This can be overriden on any `NetworkBehaviour`.
313
-
:::
314
-
315
-
On both client and server instances of this player, we call the `Move()` method, which will simply do the following.
301
+
In a networked game, the dedicated server (or host) might need to run different functions than the networked player (the client). For example, in a server-authoritative game, the client would handle the player inputs, but the server would handle the movement. All instances of this script in the game, whether running on a server/host or a client, call the `OnNetworkSpawn` method when the `NetworkObject` to which this script is attached has spawned, but only its owner will call the `Move` method. In the case of a [Player Object](../../basics/networkobject#player-objects), Netcode spawns an instance of the player object for every client and host (for which they are the owner). Each of these player objects contain this script. Calling the `Move` method in OnNetworkSpawn instead of, for example, in `Awake` ensures that the NetworkObject has finished spawning, so the check to see whether the player is a server/host or client is valid. The `Move` method can then implement different logic depending on the answer (so that servers do one thing, and clients do another).
Copy file name to clipboardExpand all lines: docs/tutorials/goldenpath_series/gp_module_two.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -149,7 +149,7 @@ Now we check that the Network Transform functions correctly.
149
149
150
150
1. Select **File** > **Build and Run**.
151
151
1. Stop the player.
152
-
1. Launch the client and server together in a terminal as shown in [Testing the command line helper](#testing-the-command-line-helper).
152
+
1. Launch the client and server together in a terminal as shown in [Testing the command line helper](../helloworld.md#testing-the-command-line-helper).
153
153
1. After a brief delay, the client and server will spawn.
154
154
1. You should see the player capsule moving in a circle on both the client and the server.
155
155
@@ -212,7 +212,7 @@ Now we will test that the client and server are both recieving the RPCs correctl
212
212
213
213
1. Select **File** > **Build and Run**.
214
214
1. Stop the player.
215
-
1. Launch the client and server together in a terminal as shown in [Testing the command line helper](#testing-the-command-line-helper).
215
+
1. Launch the client and server together in a terminal as shown in [Testing the command line helper](../helloworld.md#testing-the-command-line-helper).
216
216
1. After a brief delay, the client and server will spawn.
217
217
1. In the console, you should expect to see the client and server sending RPC messages to each other.
218
218
1. The client kicks off the exchange in its `Update` call the first time with a counter value of 0.
Copy file name to clipboardExpand all lines: docs/tutorials/helloworld.md
+8-5Lines changed: 8 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ In this section we will create the basic building blocks of a multiplayer game.
30
30
31
31
### Creating Network Manager and selecting the Transport
32
32
33
-
In this section we will add a Network Manager and add Unity Transport (UTP) to our project.
33
+
In this section we add a Network Manager and add Unity Transport (UTP) to our project. The [NetworkManager](../components/networkmanager.md) is the component that contains all your project's netcode-related settings. UTP is the transport layer that Netcode uses for communication between the server and the clients. See [here](../advanced-topics/transports.md) for more.
34
34
35
35
1. Right-click in the **Hierarchy** tab of the main Unity Window.
36
36
1. Select **Create Empty**.
@@ -89,7 +89,7 @@ When 'Enable Scene Management' is enabled for the NetworkManager (allowing the s
89
89
90
90
## Creating a command line helper
91
91
92
-
This command line helper launches our project outside Unity and can make testing builds easier.
92
+
This command line helper will allow us to launch builds with a command line argument that will start a networking session, either as a server, host, or client. This can make testing builds easier.
93
93
94
94
1. Right-click the **Assets** folder and create a new folder by hovering over **Create** and selecting **Folder**. Name it **Scripts**.
95
95
2. Create a script called `NetworkCommandLine` by right-clicking on your **Scripts** folder, hovering over **Create** and selecting **C# Script**.
@@ -290,16 +290,19 @@ import TabItem from '@theme/TabItem';
290
290
291
291
## Testing Hello World
292
292
293
-
Now we will test to see if everything works as expected.
293
+
Now, to see if everything works as expected we can test starting a host in the editor. A host plays the role of a server and a client at the same time.
294
294
295
295
1. Click **Play**.
296
-
1. Click **Start Host** under **NetworkManager**.
296
+
1. Click the **Start Host** button in the **NetworkManager** GameObject's inspector.
297
+
1. You should now see your scene with your Player Prefab spawned.
298
+
299
+
You can also use the command line helper to launch a server and one or more clients to connect to the server. You should see the plane on the server until the first client connects. Then, a new Player Prefab will be spawned by Netcode for each connected client.
297
300
298
301
## Next Steps
299
302
300
303
See the following content to continue your journey using Netcode:
301
304
302
-
* Build on the Hello World project to continue learning about different features of Netcode with the [Golden Path series](../tutorials/goldenpath_series/gp_intro.md).
305
+
* Build on the Hello World project to continue learning about different features of Netcode with the [Golden Path series](goldenpath_series/gp_intro.md).
303
306
* Check out the educational samples to further explore Netcode and its abilities:
0 commit comments