InvalidCastException on serverRpc call on Unity Editor host
See original GitHub issueDescribe the bug
A InvalidCastException: Specified cast is not valid.
exception is raised when a ServerRpc is called by a connected client.
To Reproduce With a host on the Unity Editor and a build running a client, call a serverRpc like this one:
[ServerRpc(RequireOwnership = false)]
private void ClientIsReadyServerRpc(ulong clientId)
Note that this error does not happen if both the host and client run on builds, nor if the client runs on the editor and host on build.
Actual outcome
NetworkManager.cs:1145 raises an InvalidCastException, on the following line of code:
__ntable[networkMethodId](networkBehaviour, new NetworkSerializer(queueItem.NetworkReader), rpcParams);
Error log:
InvalidCastException: Specified cast is not valid.
LobbyControl.OnClientIsReadyServerRpc__nhandler (MLAPI.NetworkBehaviour target, MLAPI.Serialization.NetworkSerializer serializer, MLAPI.Messaging.__RpcParams rpcParams) (at <496a9797041240fa8a7c3c1ccc62dffb>:0)
MLAPI.NetworkManager.InvokeRpc (MLAPI.Messaging.RpcFrameQueueItem queueItem) (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkManager.cs:1145)
MLAPI.Messaging.RpcQueueProcessor.ProcessReceiveQueue (MLAPI.NetworkUpdateStage currentStage) (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Messaging/RpcQueue/RpcQueueProcessor.cs:63)
MLAPI.Messaging.RpcQueueContainer.ProcessAndFlushRpcQueue (MLAPI.Messaging.RpcQueueContainer+RpcQueueProcessingTypes queueType, MLAPI.NetworkUpdateStage currentUpdateStage) (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Messaging/RpcQueue/RpcQueueContainer.cs:114)
MLAPI.Messaging.RpcQueueContainer.NetworkUpdate (MLAPI.NetworkUpdateStage updateStage) (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Messaging/RpcQueue/RpcQueueContainer.cs:62)
MLAPI.NetworkUpdateLoop.RunNetworkUpdateStage (MLAPI.NetworkUpdateStage updateStage) (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkUpdateLoop.cs:148)
MLAPI.NetworkUpdateLoop+NetworkUpdate+<>c.<CreateLoopSystem>b__0_0 () (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkUpdateLoop.cs:207)
Expected outcome The ServerRpc should be called without raising an exception.
Screenshots N/A
Environment (please complete the following information):
- OS: [Windows 10]
- Unity Version: [2020.3.5f1]
- MLAPI Version: [0.1.0]
- MLAPI Commit: [https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/commit/3e3aef6aa02c2a25359898319e5bd49d3518b57b]
Additional context I recently changed to the new Unity Hub beta, I had this error for the first time when running this code after that change. The same code would work fine before that. I may update this issue with a minimal project to reproduce the error if I have some time available.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
I couldn’t reproduce the bug on a new project, and after some refactoring/code cleanup on my own project the exception disapeared. In hindsight it was probably related to the fact that I was starting up the client (
NetworkManager.Singleton.StartClient()
) on a scene that had other NetworkObjects. As I am unable to reproduce this in a controlled environment I’ll leave to your discretion weather to close this issue.I’ll try to setup a minimalistic project that reproduces the error today