Search Unity

Question Need help deciphering this error message

Discussion in 'Netcode for GameObjects' started by jordansean10, Jan 1, 2022.

  1. jordansean10

    jordansean10

    Joined:
    Aug 28, 2020
    Posts:
    5
    One of my server RPCs is giving me an unhelpful error. The name of the server RPC is SpawnTracerServerRPC. This error only occurs on the server and it also only occurs when I try and Instantiate a RaycastWeapon during runtime and then try firing. If I spawn the player prefab with a RaycastWeapon the RPC works fine

    Code (CSharp):
    1. Unhandled RPC Exception:
    2. System.InvalidCastException: Specified cast is not valid.
    3.   at RaycastWeapon.SpawnTracerServerRpc__nhandler (Unity.Netcode.NetworkBehaviour target, Unity.Netcode.FastBufferReader reader, Unity.Netcode.__RpcParams rpcParams) [0x00089] in <5c3ccea7be3344c5b6b1f7bdb72225ca>:0
    4. UnityEngine.Debug:LogError (object)
    5. RaycastWeapon:SpawnTracerServerRpc__nhandler (Unity.Netcode.NetworkBehaviour,Unity.Netcode.FastBufferReader,Unity.Netcode.__RpcParams)
    6. Unity.Netcode.RpcMessage:Handle (Unity.Netcode.FastBufferReader,Unity.Netcode.NetworkContext&,Unity.Netcode.NetworkManager,ulong,bool) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.3/Runtime/Messaging/Messages/RpcMessage.cs:93)
    7. Unity.Netcode.NetworkBehaviour:__sendServerRpc (Unity.Netcode.FastBufferWriter,uint,Unity.Netcode.ServerRpcParams,Unity.Netcode.RpcDelivery) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.3/Runtime/Core/NetworkBehaviour.cs:87)
    8. RaycastWeapon:SpawnTracerServerRpc (UnityEngine.Vector3) (at Assets/Scripts/RaycastWeapon.cs:39)
    9. RaycastWeapon:Update () (at Assets/Scripts/RaycastWeapon.cs:30)
    From the error message I'm having a hard time seeing which Specific cast is failing, could someone help point me in a direction to look?
     
  2. jordansean10

    jordansean10

    Joined:
    Aug 28, 2020
    Posts:
    5
    I think I kind of figured out the issue. I was basically trying to add a nested NetworkBehaviour component to the player's NetworkObject at runtime and I suspect the RPC calls weren't working because the NetworkBehaviour wasn't being associated properly with the players NetworkObject.

    I tried adding a NetworkObject to the gameObject which contained the NetworkBehaviour but then I ended up hitting this bug I believe https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/1523