Unity-Technologies / multiplayer-community-contributions

Community contributions to Unity Multiplayer Networking products and services.
MIT License
429 stars 161 forks source link

InvalidCastException: Specified cast is not valid. #154

Open maojiahui opened 2 years ago

maojiahui commented 2 years ago

startHost Discovery Servers Error

audoraemon commented 2 years ago

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

IJsLauw commented 2 years ago

Try this: UNetTransport, the cast was wrong

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

Fangh commented 2 years ago

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 commented 2 years ago

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/com.unity.netcode.gameobjects@1.0.0-pre.6/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/com.unity.netcode.gameobjects@1.0.0-pre.6/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]
LukeStampfli commented 2 years ago

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.

timafeuse commented 7 months ago

Same problem