Description
Describe the bug
Types serialized via ReadValueSafe and WriteValueSafe cannot be used in RPCs. InvalidProgramException
is thrown.
To Reproduce
Steps to reproduce the behavior:
- Create a custom type to serialize (class/struct).
- Create custom type serialization extensions ReadValueSafe and WriteValueSafe for that type, placed in a static class SerializationExtensions as in documentation examples.
- Create Server/Client RPCs that pass our custom type as one of the parameters.
- At runtime, call the RPC.
Actual outcome
When RPC is called Unity throws the following exception (in my case):
InvalidProgramException: Invalid IL code in Code.Eclipse.ItemSystem.Player.PlayerDetails:DropItemServerRpc (Code.Eclipse.ItemSystem.EclipseItemSystem.ItemBase): IL_00dd: call 0x06000b65
RPC is not sent.
Expected outcome
The client and server should be able to send RPC containing custom type successfully,
Environment:
- OS: Windows 10
- Unity Version: 2021.2.0b16
- Netcode Version: v1.0.0-pre.2
Additional context
I use this serialization method for various purposes like replicating items via factory method pattern (classes), sending player-data (struct), or passing player object context. None of these can be passed via RPCs. Passing them via a named messaging system works as expected. Passing INetworkSerializable types in RPCs works as expected.