Skip to content

Commit 0d8396d

Browse files
Larah ArmstrongNoelStephensUnity
andauthored
Add NGO 1.1.0 documentation (#839)
* Bump version * update Adjusting the code example to be compliant with the recent updates. Adding additional information about the example in the note. * parenting update Adding some additional language to the parenting related documents and fixing a minor spelling issue. Co-authored-by: NoelStephensUnity <[email protected]>
1 parent a7f121d commit 0d8396d

File tree

234 files changed

+44552
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+44552
-9
lines changed

docs/advanced-topics/inscene_parenting_player.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ public class ParentPlayerToInSceneNetworkObject : NetworkBehaviour
4949
// As long as the client (player) is in the connected clients list
5050
if (NetworkManager.ConnectedClients.ContainsKey(clientId))
5151
{
52-
// Set the player as a child of this in-scene placed NetworkObject
53-
NetworkManager.ConnectedClients[clientId].PlayerObject.transform.parent = transform;
52+
// Set the player as a child of this in-scene placed NetworkObject
53+
// We parent in local space by setting the WorldPositionStays value to false
54+
NetworkManager.ConnectedClients[clientId].PlayerObject.TrySetParent(NetworkObject, false);
5455
}
5556
}
5657
}
@@ -83,5 +84,5 @@ You should place this script on your in-scene placed `NetworkObject` (i.e. the f
8384

8485

8586
:::note
86-
Remove any parenting code you might have had from your player prefab before using the above script.
87+
Remove any parenting code you might have had from your player prefab before using the above script. Depending upon your project's goals, you might be parenting all players under the same in-scene placed `NetworkObject` or you might intend to have each player parenting unique. If you want each player to be parented under a unique in-scene placed `NetworkObject` then you will need to have the same number of in-scene placed `NetworkObject`s as your maximum allowed players per game session. The above example will only parent all players under the same in-scene placed `NetworkObject`. You could extend the above example by migrating the scene event code into an in-scene placed `NetworkObject` that manages the parenting of players (i,e. name it something like `PlayerSpawnManager`) as they connect, make the `SetPlayerParent` method public, and add all in-scene placed `NetworkObject`s to a public list of GameObjects that the `PlayerSpawnManager` will reference and assign player's to as they connect while also freeing in-scene placed `NetworkObject`s as players disconnect during a game session.
8788
:::

docs/advanced-topics/networkobject-parenting.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Vehicle (GameObject->NetworkObject)
151151
This would be considered an invalid parenting and would be reverted.
152152

153153
### Mildly Complex Valid Example:
154-
In order to resolve the previous invalid parenting issue, we would need to add a `NetworkObjet` component to the seats. This means we would need to:
154+
In order to resolve the previous invalid parenting issue, we would need to add a `NetworkObject` component to the seats. This means we would need to:
155155
1. Spawn the vehicle and the seats:
156156
```
157157
Sun
@@ -185,8 +185,18 @@ Vehicle (GameObject->NetworkObject)
185185
└─Seat2 (GameObject->NetworkObject)
186186
```
187187

188+
### Parenting & Transform Synchronization
189+
It is important to understand that without the use of a `NetworkTransform` clients are only synchronized with the transform values when:
190+
- A client is being synchronized with the NetworkObject in question:
191+
- During the client's first synchronization after a client has their connection approved.
192+
- When a server spawns a new `NetworkObject`.
193+
- A `NetworkObject` has been parented _(or a parent removed)_.
194+
- The server can override the `NetworkBehaviour.OnNetworkObjectParentChanged` method and adjust the transform values when that is invoked.
195+
- These transform changes will be synchronized with clients via the `ParentSyncMessage`
196+
197+
188198
:::note Optional Auto Synchronized Parenting
189-
The Auto Object Parent Sync property of NetworkObject, enabled by default, allows you to disable automatic parent change synchronization in the event you want to implement your own parenting solution for one or more NetworkObjects.
199+
The Auto Object Parent Sync property of a `NetworkObject`, enabled by default, allows you to disable automatic parent change synchronization in the event you want to implement your own parenting solution for one or more NetworkObjects. It is important to understand that disabling the Auto Object Parent Sync option of a `NetworkObject` will treat the `NetworkObject`'s transform synchronization with *clients* as if its parent is the hierarchy root _(i.e. null)_.
190200
:::
191201

192202

docs/basics/scenemanagement/inscene-placed-networkobjects.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,30 @@ In-scene placed `NetworkObject`s follow the same parenting rules as [dynamically
231231
- Under this scenario, you would want to use a hybrid approach where the in-scene placed `NetworkObject` dynamically spawns the item to be picked up.
232232
- If you plan on using a bootstrap scene usage pattern where you use additive scene loading and unloading with no full scene-migration(s), then it is "OK" to parent in-scene placed NetworkObjects.
233233

234-
:::warning
235-
Parenting in-scene placed `NetworkObject`s under `GameObject`s with no `NetworkObject` component will currently synchronize the child `NetworkObject` as if it is in world space on the client side. To work around this particular issue you should add a `NetworkTransform` to the child and enable local space synchronization.
236-
:::
234+
### Auto Object Parent Sync Option & Parenting
235+
Already parented in-scene placed `NetworkObject`s Auto Object Parent Sync Usage:
236+
237+
- When disabled, the NetworkObject ignores its parent and considers all of its transform values as being world space synchronized (i.e. no matter where you move or rotate its parent, it will maintain its current position and rotation)
238+
- Typically, when disabling this you need to handle synchronizing the client either through your own custom messages or RPCS or add a NetworkTransform component to it. This is only useful if you want to have some global parent that might shift or have transform values that you don't want to impact the `NetworkObject` in question.
239+
- When enabled, the NetworkObject is aware of its parent and will treat all of its transform values as being local space synchronized.
240+
- _This also applies to being pre-parented under a `GameObject` with no `NetworkObject` component._
241+
242+
:::note
243+
_**The caveat to the above is scale**:_
244+
Scale is treated always as local space relative for pre-parented in-scene placed `NetworkObjects`. <br />
245+
246+
*For dynamically spawned NetworkObjects:* <br />
247+
It depends upon what WorldPositionStays value you use when parenting the NetworkObject in question.<br />
248+
WorldPositionStays = true: Everything is world space relative. _(default)_<br />
249+
WorldPositionStays = false: Everything is local space relative. _(children offset relative to the parent)_<br />
250+
:::
251+
252+
253+
### Parenting & Transform Synchronization
254+
It is important to understand that without the use of a `NetworkTransform` clients are only synchronized with the transform values when:
255+
- A client is being synchronized with the NetworkObject in question:
256+
- During the client's first synchronization after a client has their connection approved.
257+
- When a server spawns a new NetworkObject.
258+
- A NetworkObject has been parented (or a parent removed).
259+
- The server can override the `NetworkBehaviour.OnNetworkObjectParentChanged` method and adjust the transform values when that is invoked.
260+
- These transform changes will be synchronized with clients via the `ParentSyncMessage`

docusaurus.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,13 @@ module.exports = {
340340
lastVersion: "current",
341341
versions: {
342342
current: {
343-
label: '1.0.0',
343+
label: '1.1.0',
344344
path: 'current',
345345
},
346+
'1.0.0': {
347+
label: '1.0.0',
348+
path: '1.0.0',
349+
},
346350
'0.1.0': {
347351
label: '0.1.0',
348352
path: '0.1.0',

versioned_docs/version-1.0.0/about.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
id: about
3+
title: About Netcode for GameObjects
4+
description: Learn more about the available APIs for Unity Multiplayer Networking, including Netcode for GameObjects and Transport.
5+
---
6+
7+
Netcode for GameObjects (Netcode) is a high-level networking library built for Unity for you to abstract networking logic. It enables you to send GameObjects and world data across a networking session to multiplayer players at once. With Netcode, you can focus on building your game instead of low-level protocols and networking frameworks.
8+
9+
To learn more about Netcode for GameObjects functionality and capabilities, explore the content below:
10+
11+
<div class="table-columns-plain" >
12+
13+
| Getting Started | Hello World and Golden Paths | Education and Samples |
14+
| -- | -- | -- |
15+
| [Install Unity Netcode](installation/installation.md)<br/>[Migration from UNet to Netcode](installation/migratingfromUNet.md)<br/>[Upgrade to Unity Netcode Package](installation/migratingfrommlapi.md) | [Your First Networked Game](tutorials/helloworld.md)<br/>[Module One](tutorials/goldenpath_series/gp_module_one.md)<br/>[Module Two](tutorials/goldenpath_series/gp_module_two.md)<br/>| [Boss Room](learn/bossroom/getting-started-boss-room.md)<br/>[Bite Size Samples](learn/bitesize/bitesize-introduction.md)<br/>[Dilmer's Tutorials](learn/dilmer/dilmer-video.md) |
16+
17+
</div>
18+
19+
<div class="table-columns-plain" >
20+
21+
| Core Concepts | Debugging | Terminology and FAQs |
22+
| -- | -- | -- |
23+
| [Networking](basics/connection-approval.md)<br/>[Components](components/networkmanager.md)<br/>[Objects](basics/object-spawning.md)<br/>[Messaging System](advanced-topics/messaging-system.md)<br/>[Serialization](advanced-topics/serialization/serialization-intro.md)<br/>[Scenes](basics/scenemanagement/scene-management-overview.md) | [Logging](basics/logging.md)<br/>[Troubleshooting](troubleshooting/troubleshooting.md)<br/>[Error Messages](troubleshooting/error-messages.md) | [High Level Terminology](reference/glossary/high-level-terminology.md)<br/>[Multiplayer Game Architecture](learn/multiplayer_game_arch_intro.md)<br/>[FAQs](learn/faq.md) |
24+
25+
</div>
26+
27+
Don't forget to check out our [Release Notes](https://docs-multiplayer.unity3d.com/releases/introduction) and [APIs](api/introduction.md)!
28+
29+
## Before you begin
30+
31+
Netcode supports the following versions:
32+
* Unity 2020.3, 2021.1, 2021.2, and 2021.3
33+
* Mono and IL2CPP [Scripting Backends](https://docs.unity3d.com/Manual/scripting-backends.html)
34+
35+
Netcode supports the following platforms:
36+
* Windows, MacOS, and Linux
37+
* iOS and Android
38+
* XR platforms running on Windows, Android, and iOS operating systems
39+
* Most [**closed platforms**](https://unity.com/platform-installation), such as consoles. Contact us for more information about specific closed platforms.
40+
* When working with consoles (such as PlayStation, Xbox, or Nintendo Switch), there may be Netcode-specific policies you should be aware of while testing and before launching your game live. Refer to the console's internal documentation for more information. This content is typically protected by NDA.
41+
42+
:::caution Using WebGL
43+
Netcode does not support the WebGL platform because it does not allow access to IP Sockets.
44+
45+
There are third party transports provided by the community that may enable you to use Netcode on WebGL platforms. A list of these transports are found [here](https://github.com/Unity-Technologies/multiplayer-community-contributions#transports).
46+
47+
Use with caution:
48+
* You may encounter bugs and issues while using Netcode on WebGL, and we will not prioritize fixing those issues.
49+
* The server or host cannot be a WebGL client, but a Desktop or Mobile build.
50+
* You may experience **increased** latency and jitter because of the TCP protocol used by WebSockets.
51+
:::
52+
53+
:::unity Content Licenses
54+
This is free under the permissive MIT [Licenses](/reference/license) by Unity and the Netcode collaborators. Netcode is open source with no attached costs or limitations, so you can develop features alongside Unity.
55+
:::
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
id: bufferserializer
3+
title: BufferSerializer
4+
sidebar_label: BufferSerializer
5+
---
6+
7+
`BufferSerializer<TReaderWriter>` is the bi-directional serializer primarily used for serializing within [`INetworkSerializable`](inetworkserializable.md) types. It wraps [`FastBufferWriter` and `FastBufferReader`](fastbufferwriter-fastbufferreader.md) to provide high performance serialization, but has a couple of differences to make it more user-friendly:
8+
9+
- Rather than writing separate methods for serializing and deserializing, `BufferSerializer<TReaderWriter>` allows writing a single method that can handle both operations, which reduces the possibility of a mismatch between the two
10+
- `BufferSerializer<TReaderWriter>` does bound checking on every read and write by default, making it easier to avoid mistakes around manual bounds checking required by `FastBufferWriter` and `FastBufferReader`
11+
12+
These aren't without downsides, however:
13+
14+
- `BufferSerializer<TReaderWriter>` has to operate on an existing mutable value due to its bi-directional nature, which means values like `List<T>.Count` have to be stored to a local variable before writing.
15+
- `BufferSerializer<TReaderWriter>` is slightly slower than `FastBufferReader` and `FastBufferWriter` due to both the extra pass-through method calls and the mandatory bounds checking on each write.
16+
- `BufferSerializer<TReaderWriter>` do not support any form of packed reads and writes.
17+
18+
However, when those downsides are unreasonable, `BufferSerializer<TReaderWriter>` offers two ways to perform more optimal serialization for either performance or bandwidth usage:
19+
20+
- For performance, you can use `PreCheck(int amount)` followed by `SerializeValuePreChecked()` to perform bounds checking for multiple fields at once.
21+
- For both performance and bandwidth usage, you can obtain the wrapped underlying reader/writer via `serializer.GetFastBufferReader()` when `serializer.IsReader` is `true`, and `serializer.GetFastBufferWriter()` when `serializer.IsWriter` is `true`. These provide micro-performance improvements by removing a level of indirection, and also give you a type you can use with `BytePacker` and `ByteUnpacker`.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
id: custom-serialization
3+
title: Custom Serialization
4+
---
5+
6+
When using `RPC`'s, `NetworkVariable`'s or any other Netcode for GameObjects (Netcode) related task that requires serialization. The Netcode uses a default serialization pipeline that looks like this:
7+
8+
``
9+
Custom Types => Built In Types => INetworkSerializable
10+
``
11+
12+
That is, when Netcode first gets hold of a type, it will check for any custom types that the user have registered for serialization, after that it will check if it's a built in type, such as a Vector3, float etc. These are handled by default. If not, it will check if the type inherits `INetworkSerializable`, if it does, it will call it's write methods.
13+
14+
By default, any type that satisfies the `unmanaged` generic constraint can be automatically serialized as RPC parameters. This includes all basic types (bool, byte, int, float, enum, etc) as well as any structs that contains only these basic types.
15+
16+
With this flow, you can override **ALL** serialization for **ALL** types, even built in types, and with the API provided, it can even be done with types that you have not defined yourself, those who are behind a 3rd party wall, such as .NET types.
17+
18+
To register a custom type, or override an already handled type, you need to create extension methods for `FastBufferReader.ReadValueSafe()` and `FastBufferWriter.WriteValueSafe()`:
19+
20+
```csharp
21+
// Tells the Netcode how to serialize and deserialize Url in the future.
22+
// The class name doesn't matter here.
23+
public static class SerializationExtensions
24+
{
25+
public static void ReadValueSafe(this FastBufferReader reader, out Url value)
26+
{
27+
reader.ReadValueSafe(out string val);
28+
value = new Url(val);
29+
}
30+
31+
public static void WriteValueSafe(this FastBufferWriter writer, in Url value)
32+
{
33+
writer.WriteValueSafe(instance.Value);
34+
}
35+
}
36+
```
37+
38+
The code generation for RPCs will automatically pick up and use these functions, and they'll become available via `FastBufferWriter` and `FastBufferReader` directly.
39+
40+
You can also optionally use the same method to add support for `BufferSerializer<TReaderWriter>.SerializeValue()`, if you wish, which will make this type readily available within [`INetworkSerializable`](/advanced-topics/serialization/inetworkserializable.md) types:
41+
42+
```c#
43+
// The class name doesn't matter here.
44+
public static class SerializationExtensions
45+
{
46+
public static void SerializeValue<TReaderWriter>(this BufferSerializer<TReaderWriter> serializer, ref Url value) where TReaderWriter: IReaderWriter
47+
{
48+
if (serializer.IsReader)
49+
{
50+
value = new Url();
51+
}
52+
serializer.SerializeValue(ref value.Value);
53+
}
54+
}
55+
```
56+
57+
Additionally, you can also add extensions for `FastBufferReader.ReadValue()`, `FastBufferWriter.WriteValue()`, and `BufferSerializer<TReaderWriter>.SerializeValuePreChecked()` to provide more optimal implementations for manual serialization using `FastBufferReader.TryBeginRead()`, `FastBufferWriter.TryBeginWrite()`, and `BufferSerializer<TReaderWriter>.PreCheck()`, respectively. However, none of these will be used for serializing RPCs - only `ReadValueSafe` and `WriteValueSafe` are used.

0 commit comments

Comments
 (0)