Search Unity

Question Problem: ClientNetworkTransform with Relay - InvalidCastException: Specified cast is not valid

Discussion in 'Multiplayer' started by ViktorMSc, Jul 21, 2022.

  1. ViktorMSc

    ViktorMSc

    Joined:
    May 28, 2022
    Posts:
    14
    Hey, I'm trying to convert the 3rd person sample to a Multiplayer Game using Netcode, Lobby and Relay.

    It works when I use Unity Transport and the players movements are syncing, both host and client.

    The Relay Host and Lobby creation is also working, as well as joining a Lobby, getting Relay Join Code from Lobby and starting client and host, so they both spawn on the map.

    However, the Transform does not work when I use the Relay Transport in NetworkManager.

    Im using this to set up the Relay and start the client: https://docs.unity.com/relay/relay-and-ngo.html

    ClientNetworkTransform: https://github.com/Unity-Technologi...ClientAuthority/ClientNetworkTransform.cs#L14

    So, the host can move, but the client just sees him standing still. When the client moves, the host gets the following error. Any idea what I am doing wrong?

    Code (CSharp):
    1. InvalidCastException: Specified cast is not valid.
    2. Unity.Netcode.Components.NetworkTransform.__rpc_handler_104221529 (Unity.Netcode.NetworkBehaviour target, Unity.Netcode.FastBufferReader reader, Unity.Netcode.__RpcParams rpcParams) (at <5c49182fbd634b3f94508ffbc4041726>:0)
    3. Unity.Netcode.RpcMessageHelpers.Handle (Unity.Netcode.NetworkContext& context, Unity.Netcode.RpcMetadata& metadata, Unity.Netcode.FastBufferReader& payload, Unity.Netcode.__RpcParams& rpcParams) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0/Runtime/Messaging/Messages/RpcMessages.cs:77)
    4. Rethrow as Exception: Unhandled RPC exception!
    5. UnityEngine.Debug:LogException(Exception)
    6. Unity.Netcode.RpcMessageHelpers:Handle(NetworkContext&, RpcMetadata&, FastBufferReader&, __RpcParams&) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0/Runtime/Messaging/Messages/RpcMessages.cs:81)
    7. Unity.Netcode.ServerRpcMessage:Handle(NetworkContext&) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0/Runtime/Messaging/Messages/RpcMessages.cs:122)
    8. Unity.Netcode.MessagingSystem:ReceiveMessage(FastBufferReader, NetworkContext&, MessagingSystem) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0/Runtime/Messaging/MessagingSystem.cs:338)
    9. Unity.Netcode.MessagingSystem:HandleMessage(MessageHeader&, FastBufferReader, UInt64, Single, Int32) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0/Runtime/Messaging/MessagingSystem.cs:269)
    10. Unity.Netcode.MessagingSystem:ProcessIncomingMessageQueue() (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0/Runtime/Messaging/MessagingSystem.cs:288)
    11. Unity.Netcode.NetworkManager:OnNetworkEarlyUpdate() (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0/Runtime/Core/NetworkManager.cs:1531)
    12. Unity.Netcode.NetworkManager:NetworkUpdate(NetworkUpdateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0/Runtime/Core/NetworkManager.cs:1463)
    13. Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage(NetworkUpdateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0/Runtime/Core/NetworkUpdateLoop.cs:185)
    14. Unity.Netcode.<>c:<CreateLoopSystem>b__0_0() (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0/Runtime/Core/NetworkUpdateLoop.cs:208)
    15.