multiplayer-community-contributions icon indicating copy to clipboard operation
multiplayer-community-contributions copied to clipboard

InvalidCastException: Specified cast is not valid.

Open maojiahui opened this issue 3 years ago • 6 comments

startHost Discovery Servers Error

maojiahui avatar Feb 20 '22 04:02 maojiahui

this also happen to me. If you have any solution pls tell me.

audoraemon avatar Feb 21 '22 09:02 audoraemon

Try this: UNetTransport, the cast was wrong

Port = (ushort) ((**UNetTransport**) m_NetworkManager.NetworkConfig.NetworkTransport).ConnectPort

IJsLauw avatar Mar 07 '22 13:03 IJsLauw

The documentation tells us to use this repo for networkdiscovery : https://docs-multiplayer.unity3d.com/docs/migration/migratingtonetcode/#network-discovery

But the code doesnt buid : image

I had to change to UNetTransport :

        Port = (ushort) ((UNetTransport) m_NetworkManager.NetworkConfig.NetworkTransport).ConnectPort,

and it worked.

and also in the HUD :

image

Fangh avatar Mar 28 '22 19:03 Fangh

and it doesn't work

2022/03/28 22:25:00.635 5498 5520 Error Unity host id out of bound id {255} max id should be greater than 0 and less than {1}
2022/03/28 22:25:00.635 5498 5520 Error Unity UnityEngine.StackTraceUtility:ExtractStackTrace () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/StackTrace.cs:37)
2022/03/28 22:25:00.635 5498 5520 Error Unity Unity.Netcode.Transports.UNET.UNetTransport:SendQueued (ulong) (at S:/Unity Projects/Hypnomind/Library/PackageCache/[email protected]/Runtime/Transports/UNET/UNetTransport.cs:142)
2022/03/28 22:25:00.635 5498 5520 Error Unity Unity.Netcode.Transports.UNET.UNetTransport:LateUpdate () (at S:/Unity Projects/Hypnomind/Library/PackageCache/[email protected]/Runtime/Transports/UNET/UNetTransport.cs:63)
2022/03/28 22:25:00.635 5498 5520 Error Unity 
2022/03/28 22:25:00.635 5498 5520 Error Unity [./Modules/UNET/UNETNetLibraryManager.cpp line 587]

Fangh avatar Mar 28 '22 20:03 Fangh

The discovery uses the UnityTransport. I suggest installing the com.unity.netcode.adapter.utp package and using the UnityTransport component instead of the UnetTransport that way you don't have to change any code.

LukeStampfli avatar Mar 29 '22 14:03 LukeStampfli

Same problem

timafeuse avatar Jan 26 '24 16:01 timafeuse