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
* Sync develop with main (#868)
* Publish staged content (#852)
* Merging Develop with Main (#813) (#826)
* Updating docs page in 2D space shooter (#810)
Updating docs page in 2D space shooter which has a reference to an unconfirmed feature (Prediction)
* updating boss room example used in mid-game reconnecting doc (#725)
Co-authored-by: Sara [Unity] <[email protected]>
Co-authored-by: Christopher Pope <[email protected]>
* Update getting-started-boss-room.md (#812)
Co-authored-by: LPLafontaineB <[email protected]>
Co-authored-by: Sara [Unity] <[email protected]>
Co-authored-by: Sam Bellomo <[email protected]>
Co-authored-by: Christopher Pope <[email protected]>
Co-authored-by: LPLafontaineB <[email protected]>
Co-authored-by: Sara [Unity] <[email protected]>
Co-authored-by: Sam Bellomo <[email protected]>
* small fixes for tutorials (#829)
* renamed command line argument and variable in helloworld code snippet
* fixing broken link in gp module 2
* fixing indentation issues in gp 1 code snippets
* fixing log not corresponding to code example
* updating gp table of contents
* removing unneeded instructions
* Update NGO changelog to 1.1.0 (#834)
* Update NGO changelog to 1.1.0
* Add PR and issue links
* In-Scene Placed NetworkObject updates for v1.1.0 (#816)
* Merging Develop with Main (#813)
* Updating docs page in 2D space shooter (#810)
Updating docs page in 2D space shooter which has a reference to an unconfirmed feature (Prediction)
* updating boss room example used in mid-game reconnecting doc (#725)
Co-authored-by: Sara [Unity] <[email protected]>
Co-authored-by: Christopher Pope <[email protected]>
* Update getting-started-boss-room.md (#812)
Co-authored-by: LPLafontaineB <[email protected]>
Co-authored-by: Sara [Unity] <[email protected]>
Co-authored-by: Sam Bellomo <[email protected]>
* Start 1.1.0 updates
Just creating a branch to start working on v1.1.0 updates
* update
updated the spawning and despawning portion.
* update
Final first pass for in-scene placed NetworkObject documentation updates.
* update
adding temporary warning to users about in-scene placed NetworkObject parenting.
Co-authored-by: Christopher Pope <[email protected]>
Co-authored-by: LPLafontaineB <[email protected]>
Co-authored-by: Sara [Unity] <[email protected]>
Co-authored-by: Sam Bellomo <[email protected]>
* WorldPositionStays update (#778)
* WorldPositionStays update
The update to this documentation requires NGO SDK PR-2146 before it should be made public/merged.
* update
Still WIP
* update
additions and adjustments.
* update
* update
final pass adjustments for the PRs suggested updates.
Co-authored-by: Christopher Pope <[email protected]>
Co-authored-by: Larah Armstrong <[email protected]>
* Remove internal comment (#830)
* update ClientNetworkTransform information (#791)
* update ClientNetworkTransform information
This just provides users with a bit more information about setting NetworkTransform into owner/client authoritative mode,
* update
adjusting the text copy and pointing the example of the ClientNetworkTransform to the co-op samples version
* update
Applying suggested update for section that outlines how to add the multiplayer samples utilities package to your project.
Co-authored-by: Christopher Pope <[email protected]>
Co-authored-by: Larah Armstrong <[email protected]>
* Updated existing or added missing dark themes to our sequence and scene diagrams! (#838)
Co-authored-by: Larah Armstrong <[email protected]>
* 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]>
* NGO 1.1.0 release notes (#843)
* Fix version drop-down order
* Add NGO 1.1.0 release notes
* fix: tutorial improvements (#840)
* 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]>
* Add "coming soon" note to empty pages (#845)
* Add Optimizing Boss Room Performance
* Revert "Add Optimizing Boss Room Performance"
This reverts commit 427c1f2.
* Add Optimizing Boss Room Performance (#848)
* Add Optimizing Boss Room Performance
* Minor fixes
* Implement feedback
* Fix SceneEventType Typo (#850)
* Publish staged content (#844)
* Merging Develop with Main (#813) (#826)
* Updating docs page in 2D space shooter (#810)
Updating docs page in 2D space shooter which has a reference to an unconfirmed feature (Prediction)
* updating boss room example used in mid-game reconnecting doc (#725)
Co-authored-by: Sara [Unity] <[email protected]>
Co-authored-by: Christopher Pope <[email protected]>
* Update getting-started-boss-room.md (#812)
Co-authored-by: LPLafontaineB <[email protected]>
Co-authored-by: Sara [Unity] <[email protected]>
Co-authored-by: Sam Bellomo <[email protected]>
Co-authored-by: Christopher Pope <[email protected]>
Co-authored-by: LPLafontaineB <[email protected]>
Co-authored-by: Sara [Unity] <[email protected]>
Co-authored-by: Sam Bellomo <[email protected]>
* small fixes for tutorials (#829)
* renamed command line argument and variable in helloworld code snippet
* fixing broken link in gp module 2
* fixing indentation issues in gp 1 code snippets
* fixing log not corresponding to code example
* updating gp table of contents
* removing unneeded instructions
* Update NGO changelog to 1.1.0 (#834)
* Update NGO changelog to 1.1.0
* Add PR and issue links
* In-Scene Placed NetworkObject updates for v1.1.0 (#816)
* Merging Develop with Main (#813)
* Updating docs page in 2D space shooter (#810)
Updating docs page in 2D space shooter which has a reference to an unconfirmed feature (Prediction)
* updating boss room example used in mid-game reconnecting doc (#725)
Co-authored-by: Sara [Unity] <[email protected]>
Co-authored-by: Christopher Pope <[email protected]>
* Update getting-started-boss-room.md (#812)
Co-authored-by: LPLafontaineB <[email protected]>
Co-authored-by: Sara [Unity] <[email protected]>
Co-authored-by: Sam Bellomo <[email protected]>
* Start 1.1.0 updates
Just creating a branch to start working on v1.1.0 updates
* update
updated the spawning and despawning portion.
* update
Final first pass for in-scene placed NetworkObject documentation updates.
* update
adding temporary warning to users about in-scene placed NetworkObject parenting.
Co-authored-by: Christopher Pope <[email protected]>
Co-authored-by: LPLafontaineB <[email protected]>
Co-authored-by: Sara [Unity] <[email protected]>
Co-authored-by: Sam Bellomo <[email protected]>
* WorldPositionStays update (#778)
* WorldPositionStays update
The update to this documentation requires NGO SDK PR-2146 before it should be made public/merged.
* update
Still WIP
* update
additions and adjustments.
* update
* update
final pass adjustments for the PRs suggested updates.
Co-authored-by: Christopher Pope <[email protected]>
Co-authored-by: Larah Armstrong <[email protected]>
* Remove internal comment (#830)
* update ClientNetworkTransform information (#791)
* update ClientNetworkTransform information
This just provides users with a bit more information about setting NetworkTransform into owner/client authoritative mode,
* update
adjusting the text copy and pointing the example of the ClientNetworkTransform to the co-op samples version
* update
Applying suggested update for section that outlines how to add the multiplayer samples utilities package to your project.
Co-authored-by: Christopher Pope <[email protected]>
Co-authored-by: Larah Armstrong <[email protected]>
* Updated existing or added missing dark themes to our sequence and scene diagrams! (#838)
Co-authored-by: Larah Armstrong <[email protected]>
* 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]>
* NGO 1.1.0 release notes (#843)
* Fix version drop-down order
* Add NGO 1.1.0 release notes
* fix: tutorial improvements (#840)
* 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]>
* Add "coming soon" note to empty pages (#845)
* Add Optimizing Boss Room Performance
* Revert "Add Optimizing Boss Room Performance"
This reverts commit 427c1f2.
Co-authored-by: Christopher Pope <[email protected]>
Co-authored-by: LPLafontaineB <[email protected]>
Co-authored-by: Sara [Unity] <[email protected]>
Co-authored-by: Sam Bellomo <[email protected]>
Co-authored-by: Noel Stephens <[email protected]>
Co-authored-by: Jil Franco <[email protected]>
Co-authored-by: NoelStephensUnity <[email protected]>
* Fix SceneEventType Typo
LoadEvenetCompleted should be LoadEventCompleted.
Refer to: https://docs-multiplayer.unity3d.com/netcode/current/api/Unity.Netcode.SceneEventType/index.html
Co-authored-by: Larah Armstrong <[email protected]>
Co-authored-by: Christopher Pope <[email protected]>
Co-authored-by: LPLafontaineB <[email protected]>
Co-authored-by: Sara [Unity] <[email protected]>
Co-authored-by: Sam Bellomo <[email protected]>
Co-authored-by: Noel Stephens <[email protected]>
Co-authored-by: Jil Franco <[email protected]>
Co-authored-by: NoelStephensUnity <[email protected]>
* Simplify Boss Room Get started page (#851)
* Make Get started reflect the README
* Implement suggestions
* Info about ParrelSync with Unity Authentication (#795)
* Info about ParrelSync with Unity Authentication
Add some information about using ParrelSync with Unity Authentication.
Include a code snippet showing how to use the ClonesManager to automatically switch player profiles.
* Implement suggested changes
Co-authored-by: Christopher Pope <[email protected]>
Co-authored-by: Larah Armstrong <[email protected]>
Co-authored-by: Larah Armstrong <[email protected]>
* Add Network Simulator documentation (#853)
* Add Network Simulator docs
* Add to sidebar
* Fix hard line breaks
* Implement suggested changes
* Implement suggested changes
* Add versioning for Tools and switch the latest to 1.1.0
* Add Tools 1.1.0 SDK documentation
* Remove test pages (#862)
Co-authored-by: Christopher Pope <[email protected]>
Co-authored-by: LPLafontaineB <[email protected]>
Co-authored-by: Sara [Unity] <[email protected]>
Co-authored-by: Sam Bellomo <[email protected]>
Co-authored-by: Noel Stephens <[email protected]>
Co-authored-by: Jil Franco <[email protected]>
Co-authored-by: NoelStephensUnity <[email protected]>
Co-authored-by: Hunter <[email protected]>
Co-authored-by: Ben Randall <[email protected]>
* Fixed typo in messaging-system.md (#864)
NetworkVariables was spelt *Newt*orkVariable (lol)
* Update networkobject.md (#860)
Co-authored-by: Larah Armstrong <[email protected]>
* docs: fix broken copy/paste link (#855)
This fixes the broken copy/paste link for adding the Multiplayer Samples Utilities package.
Co-authored-by: Larah Armstrong <[email protected]>
Co-authored-by: Christopher Pope <[email protected]>
Co-authored-by: LPLafontaineB <[email protected]>
Co-authored-by: Sara [Unity] <[email protected]>
Co-authored-by: Sam Bellomo <[email protected]>
Co-authored-by: Noel Stephens <[email protected]>
Co-authored-by: Jil Franco <[email protected]>
Co-authored-by: NoelStephensUnity <[email protected]>
Co-authored-by: Hunter <[email protected]>
Co-authored-by: Ben Randall <[email protected]>
Co-authored-by: Walter Hulsebos <[email protected]>
Co-authored-by: Alex Robinson <[email protected]>
Co-authored-by: Jonas Lagoni <[email protected]>
* Update PR template with warning (#869)
* Fixed misleading example about NetworkList (#854)
Fixed misleading example about NetworkList, and added a more extensive example to display how to react on NetworkList changes specifically on the server/client
Co-authored-by: Larah Armstrong <[email protected]>
* Update ClientDriven.md with updated scripting references (#865)
Co-authored-by: Larah Armstrong <[email protected]>
* chore: Managed Netvar documentation (#818)
* Update UTP 2.0 documentation (#875)
* Update UTP 2.0 documentation
* Add images
* Fix pipeline image
* Swap pipeline image order
Co-authored-by: Christopher Pope <[email protected]>
Co-authored-by: LPLafontaineB <[email protected]>
Co-authored-by: Sara [Unity] <[email protected]>
Co-authored-by: Sam Bellomo <[email protected]>
Co-authored-by: Noel Stephens <[email protected]>
Co-authored-by: Jil Franco <[email protected]>
Co-authored-by: NoelStephensUnity <[email protected]>
Co-authored-by: Hunter <[email protected]>
Co-authored-by: Ben Randall <[email protected]>
Co-authored-by: Walter Hulsebos <[email protected]>
Co-authored-by: Alex Robinson <[email protected]>
Co-authored-by: Jonas Lagoni <[email protected]>
Co-authored-by: Paolo Abela <[email protected]>
Co-authored-by: Fernando Cortez <[email protected]>
Co-authored-by: Kitty Draper <[email protected]>
Copy file name to clipboardExpand all lines: docs/advanced-topics/custom-serialization.md
+39-11Lines changed: 39 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ id: custom-serialization
3
3
title: Custom Serialization
4
4
---
5
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:
6
+
Netcode uses a default serialization pipeline when using `RPC`s, `NetworkVariable`s, or any other Netcode-related tasks that require serialization. The serialization pipeline looks like this:
7
7
8
8
``
9
9
Custom Types => Built In Types => INetworkSerializable
@@ -13,7 +13,9 @@ That is, when Netcode first gets hold of a type, it will check for any custom ty
13
13
14
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
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.
16
+
With this flow, you can provide support for serializing any unsupported 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. However, the way custom serialization is implemented for RPCs and NetworkVariables is slightly different.
17
+
18
+
### For RPCs
17
19
18
20
To register a custom type, or override an already handled type, you need to create extension methods for `FastBufferReader.ReadValueSafe()` and `FastBufferWriter.WriteValueSafe()`:
19
21
@@ -22,15 +24,15 @@ To register a custom type, or override an already handled type, you need to crea
@@ -39,19 +41,45 @@ The code generation for RPCs will automatically pick up and use these functions,
39
41
40
42
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:
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.
59
+
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.
60
+
61
+
### For NetworkVariable
62
+
63
+
`NetworkVariable` goes through a slightly different pipeline than `RPC`s and relies on a different process for determining how to serialize its types. As a result, making a custom type available to the `RPC` pipeline doesn't automatically make it available to the `NetworkVariable` pipeline, and vice-versa. The same method can be used for both, but currently, `NetworkVariable` requires an additional runtime step to make it aware of the methods.
64
+
65
+
To add custom serialization support in `NetworkVariable`, follow the steps from the "For RPCs" section to write extension methods for `FastBufferReader` and `FastBufferWriter`; then, somewhere in your application startup (before any `NetworkVariable`s using the affected types will be serialized) add the following:
Netcode's serialization system natively supports Unity's Fixed String types (`FixedString32`, `FixedString64`, `FixedString128`, `FixedString512`, and `FixedString4096`). The serialization system intelligently understands these fixed string types and ensures that only the amount of the string in use is serialized, even for the larger types. This native support ensures Netcode uses no more bandwidth than is necessary.
The `INetworkSerializable` interface can be used to define custom serializable types.
8
8
9
-
:::caution
10
-
All examples provided will work with RPCs and custom messages but some examples will not work with `NetworkVariable` due to the unmanaged type restriction.<br/>
11
-
**NetworkVariable Type Litmus Test for INetworkSerializable Implementations:**
12
-
- If the implementation itself can be a null (i.e. a class), then it cannot be used
13
-
- If it contains any property that can be null (i.e. arrays), then it cannot be used
14
-
15
-
The alternative is to create your own `NetworkVariableBase` derived `type` specific class.
16
-
:::
17
-
18
9
```csharp
19
10
structMyComplexStruct : INetworkSerializable
20
11
{
@@ -68,10 +59,13 @@ As you have more control over serialization of a struct, you might implement con
68
59
More advanced use-cases are explored in following examples.
69
60
70
61
### Example: Array
71
-
:::caution
72
-
The below `INetworkSerializable` implementation example works only with RPCs and/or custom messages. The below implementation uses an array within an `INetworkSerializable` implementation. Arrays can be `null` and are not supported by the `NetworkVariable` class. As an alternative, you can write your own `NetworkVariableBase` derived class that does support managed or unmanaged value types.<br/>
73
-
[Read More About Custom NetworkVariable Implementations](../../basics/networkvariable.md)
74
-
:::
62
+
63
+
You can use arrays in one of two ways:
64
+
65
+
1. Via C# arrays
66
+
2. Via Native Collections (that is, `NativeArray`)
67
+
68
+
The critical distinction between the two is that **C# arrays** convert any type that contains the arrays to a managed type. This results in garbage collection overhead and makes the arrays somewhat less optimized when you use them with `NetworkVariable`. On the other hand, `NativeArray` requires manual memory management.
75
69
76
70
```csharp
77
71
publicstructMyCustomStruct : INetworkSerializable
@@ -103,6 +97,54 @@ public struct MyCustomStruct : INetworkSerializable
The `INetworkSerializeByMemcpy` interface is used to mark an unmanaged struct type as being trivially serializable over the network by directly copying the whole struct, byte-for-byte, as it appears in memory, into and out of the buffer. This can offer some benefits for performance compared to serializing one field at a time, especially if the struct has many fields in it, but it may be less efficient from a bandwidth-usage perspective, as fields will often be padded for memory alignment and you won't be able to "pack" any of the fields to optimize for space usage.
8
+
9
+
The interface itself has no methods in it - it's an empty interface that satisfies a constraint on methods that perform this type of serialization, primarily there to ensure that memcpy serialization isn't performed by accident on structs that don't support it.
10
+
11
+
```csharp
12
+
publicstructMyStruct : INetworkSerializeByMemcpy
13
+
{
14
+
publicintA;
15
+
publicintB;
16
+
publicfloatC;
17
+
publicboolD;
18
+
}
19
+
```
20
+
21
+
If you have a type you wish to serialize that you know is compatible with this method of serialization, but don't have access to modify the struct to add this interface, you can wrap your values in `ForceNetworkSerializeByMemcpy` to enable it to be serialized this way. This works in both `RPC`s and `NetworkVariables`, as well as in other contexts such as `BufferSerializer<>`, `FastBufferReader`, and `FastBufferWriter`.
Take care with using `INetworkSerializeByMemcpy`, and especially `ForceNetworkSerializeByMemcpy`, because not all unmanaged structs are actually compatible with this type of serialization. Anything that includes pointer types (including Native Collections like `NativeArray<>`) will not function correctly when serialized this way, and will likely cause memory corruption or crashes on the receiving side.
Copy file name to clipboardExpand all lines: docs/advanced-topics/serialization/serialization-arrays.md
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -42,3 +42,6 @@ public class StringContainer : INetworkSerializable
42
42
}
43
43
```
44
44
45
+
### Native Containers
46
+
47
+
Native containers, like `NativeArray`, are not natively supported as `RPC` parameters. However, custom support can be added for them; see [Custom Serialization](../custom-serialization.md)
0 commit comments