Skip to content

Commit 38079c9

Browse files
chore: migrate quick start fixes to v2.x.x. branch (#3787)
* update Bringing changes from the docs PR-1452 over to v2.x documentation. * update change log entry
1 parent 6153519 commit 38079c9

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
2424

2525
### Fixed
2626

27+
- Fixed issues with the "Client-server quickstart for Netcode for GameObjects" script having static methods and properties. (#3787)
2728
- Fixed issue where invoking an RPC, on another `NetworkBehaviour` associated with the same `NetworkObject` that is ordered before the `NetworkBehaviour` invoking the RPC, during `OnNetworkSpawn` could throw an exception if scene management is disabled. (#3782)
2829
- Fixed issue where the `Axis to Synchronize` toggles didn't work with multi object editing in `NetworkTransform`. (#3781)
2930

com.unity.netcode.gameobjects/Documentation~/tutorials/get-started-with-ngo.md

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,20 @@ using UnityEngine;
142142

143143
namespace HelloWorld
144144
{
145+
/// <summary>
146+
/// Add this component to the same GameObject as
147+
/// the NetworkManager component.
148+
/// </summary>
145149
public class HelloWorldManager : MonoBehaviour
146150
{
147151
private NetworkManager m_NetworkManager;
148152

149-
void Awake()
153+
private void Awake()
150154
{
151155
m_NetworkManager = GetComponent<NetworkManager>();
152156
}
153157

154-
void OnGUI()
158+
private void OnGUI()
155159
{
156160
GUILayout.BeginArea(new Rect(10, 10, 300, 300));
157161
if (!m_NetworkManager.IsClient && !m_NetworkManager.IsServer)
@@ -168,14 +172,14 @@ namespace HelloWorld
168172
GUILayout.EndArea();
169173
}
170174

171-
static void StartButtons()
175+
private void StartButtons()
172176
{
173177
if (GUILayout.Button("Host")) m_NetworkManager.StartHost();
174178
if (GUILayout.Button("Client")) m_NetworkManager.StartClient();
175179
if (GUILayout.Button("Server")) m_NetworkManager.StartServer();
176180
}
177181

178-
static void StatusLabels()
182+
private void StatusLabels()
179183
{
180184
var mode = m_NetworkManager.IsHost ?
181185
"Host" : m_NetworkManager.IsServer ? "Server" : "Client";
@@ -185,11 +189,11 @@ namespace HelloWorld
185189
GUILayout.Label("Mode: " + mode);
186190
}
187191

188-
static void SubmitNewPosition()
192+
private void SubmitNewPosition()
189193
{
190194
if (GUILayout.Button(m_NetworkManager.IsServer ? "Move" : "Request Position Change"))
191195
{
192-
if (m_NetworkManager.IsServer && !m_NetworkManager.IsClient )
196+
if (m_NetworkManager.IsServer && !m_NetworkManager.IsClient)
193197
{
194198
foreach (ulong uid in m_NetworkManager.ConnectedClientsIds)
195199
m_NetworkManager.SpawnManager.GetPlayerNetworkObject(uid).GetComponent<HelloWorldPlayer>().Move();
@@ -215,14 +219,14 @@ In your Hello World project, you created a NetworkManager by adding the pre-crea
215219
The `HelloWorldManager.cs` script accomplishes this menu within the `StartButtons().` After you select a button, the `StatusLabels()`method adds a label on-screen to display which mode you have selected. This helps distinguish Game view windows from each other when testing your multiplayer game.
216220

217221
```csharp
218-
static void StartButtons()
222+
private void StartButtons()
219223
{
220224
if (GUILayout.Button("Host")) NetworkManager.Singleton.StartHost();
221225
if (GUILayout.Button("Client")) NetworkManager.Singleton.StartClient();
222226
if (GUILayout.Button("Server")) NetworkManager.Singleton.StartServer();
223227
}
224228

225-
static void StatusLabels()
229+
private void StatusLabels()
226230
{
227231
var mode = NetworkManager.Singleton.IsHost ?
228232
"Host" : NetworkManager.Singleton.IsServer ? "Server" : "Client";
@@ -274,7 +278,7 @@ public class RpcTest : NetworkBehaviour
274278
}
275279

276280
[Rpc(SendTo.ClientsAndHost)]
277-
void ClientAndHostRpc(int value, ulong sourceNetworkObjectId)
281+
private void ClientAndHostRpc(int value, ulong sourceNetworkObjectId)
278282
{
279283
Debug.Log($"Client Received the RPC #{value} on NetworkObject #{sourceNetworkObjectId}");
280284
if (IsOwner) //Only send an RPC to the owner of the NetworkObject
@@ -284,7 +288,7 @@ public class RpcTest : NetworkBehaviour
284288
}
285289

286290
[Rpc(SendTo.Server)]
287-
void ServerOnlyRpc(int value, ulong sourceNetworkObjectId)
291+
private void ServerOnlyRpc(int value, ulong sourceNetworkObjectId)
288292
{
289293
Debug.Log($"Server Received the RPC #{value} on NetworkObject #{sourceNetworkObjectId}");
290294
ClientAndHostRpc(value, sourceNetworkObjectId);
@@ -375,7 +379,7 @@ namespace HelloWorld
375379
}
376380

377381
[Rpc(SendTo.Server)]
378-
void SubmitPositionRequestRpc(RpcParams rpcParams = default)
382+
private void SubmitPositionRequestRpc(RpcParams rpcParams = default)
379383
{
380384
var randomPosition = GetRandomPositionOnPlane();
381385
transform.position = randomPosition;
@@ -387,7 +391,7 @@ namespace HelloWorld
387391
return new Vector3(Random.Range(-3f, 3f), 1f, Random.Range(-3f, 3f));
388392
}
389393

390-
void Update()
394+
private void Update()
391395
{
392396
transform.position = Position.Value;
393397
}
@@ -408,7 +412,7 @@ public class HelloWorldPlayer : NetworkBehaviour
408412
For multiplayer games, every object runs on at least two machines: player one and player two. Because of this, you need to ensure both machines have the same behavior and have the correct information about the object. One of the instances that come into play then is to understand how the Player moves. Only one player controls how the Player object moves. The following code enforces this by validating if the machine running the code is the player's owner.
409413

410414
```csharp
411-
public override void OnNetworkSpawn()
415+
public override void OnNetworkSpawn()
412416
{
413417
if (IsOwner)
414418
{
@@ -430,14 +434,14 @@ If the current player is the server, the code determines a random position to sp
430434
}
431435

432436
[Rpc(SendTo.Server)]
433-
void SubmitPositionRequestRpc(RpcParams rpcParams = default)
437+
private void SubmitPositionRequestRpc(RpcParams rpcParams = default)
434438
{
435439
var randomPosition = GetRandomPositionOnPlane();
436440
transform.position = randomPosition;
437441
Position.Value = randomPosition;
438442
}
439443

440-
void Update()
444+
private void Update()
441445
{
442446
transform.position = Position.Value;
443447
}
@@ -458,8 +462,8 @@ You can call this `Rpc` when the player is a client or a server. When you call a
458462
The `Rpc` sets the position NetworkVariable on the server's instance of the player by just picking a random point on the plane.
459463

460464
```csharp
461-
[Rpc(SendTo.Server)]
462-
void SubmitPositionRequestRpc(RpcParams rpcParams = default)
465+
[Rpc(SendTo.Server)]
466+
private void SubmitPositionRequestRpc(RpcParams rpcParams = default)
463467
{
464468
var randomPosition = GetRandomPositionOnPlane();
465469
transform.position = randomPosition;
@@ -470,7 +474,7 @@ The `Rpc` sets the position NetworkVariable on the server's instance of the play
470474
The server instance of the player modifies the `Position` `NetworkVariable` through the `Rpc`. If the player is a client, it must apply the position locally inside the `Update` loop. (Since the two values are the same on the server, the server can run the same logic with no side effects, but you could also add `if(IsClient)` here.)
471475

472476
```csharp
473-
void Update()
477+
private void Update()
474478
{
475479
transform.position = Position.Value;
476480
}
@@ -479,7 +483,7 @@ The server instance of the player modifies the `Position` `NetworkVariable` thro
479483
Because the `HelloWorldPlayer.cs` script handles the position NetworkVariable, the `HelloWorldManager.cs` script can define the contents of `SubmitNewPosition()`.
480484

481485
```csharp
482-
static void SubmitNewPosition()
486+
private void SubmitNewPosition()
483487
{
484488
if (GUILayout.Button(NetworkManager.Singleton.IsServer ? "Move" : "Request Position Change"))
485489
{
@@ -550,7 +554,7 @@ using UnityEngine;
550554

551555
public class NetworkTransformTest : NetworkBehaviour
552556
{
553-
void Update()
557+
private void Update()
554558
{
555559
if (IsServer)
556560
{

0 commit comments

Comments
 (0)