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
Copy file name to clipboardExpand all lines: com.unity.netcode.gameobjects/Documentation~/advanced-topics/serialization/inetworkserializable.md
+52Lines changed: 52 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -181,3 +181,55 @@ public struct MyStructB : MyStructA
181
181
}
182
182
}
183
183
```
184
+
185
+
## Generic IEquatable network variables
186
+
187
+
Generic `INetworkSerializable` types with generic `IEquatable` are not supported, implemented as `public class NotSupported<T> : INetworkSerializable, IEquatable<NotSupported<T>>` where the type would be passed in during declaration like `NetworkVariable<NotSupported<int>> myVar;`.
188
+
189
+
The recommended workaround for this would be to create the generic class as usual but add a virtual method for handling the serialization of the type. Then wrap this generic `INetworkSerializable` in a derived class which then needs to have a serializable type defined where the implementation for the serialization is provided.
190
+
191
+
For example:
192
+
193
+
```csharp
194
+
publicclassMyGameData<T> : INetworkSerializable
195
+
{
196
+
// This needs to be a serializable type according to what network variables support
Copy file name to clipboardExpand all lines: com.unity.netcode.gameobjects/Documentation~/basics/networkvariable.md
-52Lines changed: 0 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -621,55 +621,3 @@ public class TestFixedString : NetworkBehaviour
621
621
622
622
> [!NOTE]
623
623
> The above example uses a pre-set list of strings to cycle through for example purposes only. If you have a predefined set of text strings as part of your actual design then you would not want to use a FixedString to handle synchronizing the changes to `m_TextString`. Instead, you would want to use a `uint` for the type `T` where the `uint` was the index of the string message to apply to `m_TextString`.
624
-
625
-
## Generic IEquatable network variables
626
-
627
-
Generic `INetworkSerializable` types with generic `IEquatable` are not supported, implemented as `public class NotSupported<T> : INetworkSerializable, IEquatable<NotSupported<T>>` where the type would be passed in during declaration like `NetworkVariable<NotSupported<int>> myVar;`.
628
-
629
-
The recommended workaround for this would be to create the generic class as usual but add a virtual method for handling the serialization of the type. Then wrap this generic `INetworkSerializable` in a derived class which then needs to have a serializable type defined where the implementation for the serialization is provided.
630
-
631
-
For example:
632
-
633
-
```csharp
634
-
publicclassMyGameData<T> : INetworkSerializable
635
-
{
636
-
// This needs to be a serializable type according to what network variables support
0 commit comments