Unity-Technologies / com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.13k stars 433 forks source link

[Netcode] Received a packet with an invalid Magic Value #2794

Closed zanthous closed 9 months ago

zanthous commented 9 months ago

Description

[Netcode] Received a packet with an invalid Magic Value. Please report this to the Netcode for GameObjects team at https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues and include the following data: Offset: 0, Size: 16, Full receive array: 01 00 00 00 08 00 00 00 bf ff 1b 03 00 00 00 00 UnityEngine.Debug:LogError (object) Unity.Netcode.NetworkLog:LogError (string) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Logging/NetworkLog.cs:34) Unity.Netcode.NetworkMessageManager:HandleIncomingData (ulong,System.ArraySegment1,single) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Messaging/NetworkMessageManager.cs:254) Unity.Netcode.NetworkConnectionManager:DataEventHandler (ulong,System.ArraySegment1&,single) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Connection/NetworkConnectionManager.cs:333) Unity.Netcode.NetworkConnectionManager:HandleNetworkEvent (Unity.Netcode.NetworkEvent,ulong,System.ArraySegment`1,single) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Connection/NetworkConnectionManager.cs:261) Unity.Netcode.NetworkConnectionManager:PollAndHandleNetworkEvents () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Connection/NetworkConnectionManager.cs:238) Unity.Netcode.NetworkManager:NetworkUpdate (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Core/NetworkManager.cs:40) Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Core/NetworkUpdateLoop.cs:185) Unity.Netcode.NetworkUpdateLoop/NetworkEarlyUpdate/<>c:b__0_0 () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.6.0/Runtime/Core/NetworkUpdateLoop.cs:208)

I'm using unity's multiplayer package with https://github.com/Unity-Technologies/multiplayer-community-contributions?path=/Transports/com.community.netcode.transport.steamnetworkingsockets this transport, and every .Send() just has this error. I tried sending a different amount of data and got this instead [Netcode] Received a packet too small to contain a BatchHeader. Ignoring it.

Is there something else I should be doing? The clients seem to connect to each other fine from what I can tell, they both log that the connection is accepted. I've never used this stuff before so there could be extra setup required or something, I just do pretty basic stuff like this:

'networkManager.StartHost()'

'transport.Initialize(networkManager); transport.ConnectToSteamID = idToConnectTo; NetworkManager.Singleton.StartClient();'

var result = transport.PollEvent(out var clientId, out var payload, out var recieveTime); if(result == Unity.Netcode.NetworkEvent.Connect) { NetworkGameDefinition networkGameDefinition = new NetworkGameDefinition { mode = GameDef.mode, shapesDropped = GameDef.gameSettings.shapesDropped, modifiers = GameDef.modifiers, }; //send gamedef to other player ArraySegment<byte> bytes = new ArraySegment<byte>(MemoryPack.MemoryPackSerializer.Serialize<NetworkGameDefinition>(networkGameDefinition)); transport.Send(clientId, bytes, Unity.Netcode.NetworkDelivery.Reliable); waitingForOtherPlayerToLoad = true; }

Later I tried updating unity to 2022.3.15f1, and netcode to 1.7.1, and using rpcs instead of transport.send. This is what happens then:

SteamNetworkingSocketsTransport - connection request to was accepted!

[Netcode] Trying to get the NGO client ID map for the transport ID ([id]) but did not find the map entry! Returning default transport ID value.

[Netcode] A ConnectionRequestMessage was received from a client when the connection has already been established. This should not happen. Please report this to the Netcode for GameObjects team at https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues and include the following data: Message Size: 94. Message Content: 02 01 7d 9a e2 a5 01 b2 36 17 b3 01 46 c4 ca 04 01 39 3b e8 2c 01 ab c9 50 60 01 53 a3 38 44 01 d3 f6 1c b8 01 a6 22 89 97 01 b5 fe 01 74 01 be 97 be 73 01 9d 9a 5c 01 01 e9 51 97 17 01 8a f7 e7 83 01 42 7f 88 c6 01 97 a3 f5 46 01 00 00 00 00 01 10 18 2b 35 41 b3 79 0e 00 00 00 00 UnityEngine.Debug:LogError (object) Unity.Netcode.NetworkLog:LogError (string) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.7.1/Runtime/Logging/NetworkLog.cs:34) Unity.Netcode.NetworkManagerHooks:OnVerifyCanReceive (ulong,System.Type,Unity.Netcode.FastBufferReader,Unity.Netcode.NetworkContext&) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.7.1/Runtime/Messaging/NetworkManagerHooks.cs:79) Unity.Netcode.NetworkMessageManager:CanReceive (ulong,System.Type,Unity.Netcode.FastBufferReader,Unity.Netcode.NetworkContext&) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.7.1/Runtime/Messaging/NetworkMessageManager.cs:327) Unity.Netcode.NetworkMessageManager:HandleMessage (Unity.Netcode.NetworkMessageHeader&,Unity.Netcode.FastBufferReader,ulong,single,int) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.7.1/Runtime/Messaging/NetworkMessageManager.cs:409) Unity.Netcode.NetworkMessageManager:ProcessIncomingMessageQueue () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.7.1/Runtime/Messaging/NetworkMessageManager.cs:460) Unity.Netcode.NetworkManager:NetworkUpdate (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.7.1/Runtime/Core/NetworkManager.cs:45) Unity.Netcode.NetworkUpdateLoop:RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.7.1/Runtime/Core/NetworkUpdateLoop.cs:185) Unity.Netcode.NetworkUpdateLoop/NetworkEarlyUpdate/<>c:b__0_0 () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.7.1/Runtime/Core/NetworkUpdateLoop.cs:208)

SteamNetworkingSocketsTransport - connection closed for [id] state responce: k_ESteamNetworkingConnectionState_ClosedByPeer UnityEngine.Debug:Log (object)

It's of course possbile these two issues are completely unrelated. What might I be missing?

Environment

zanthous commented 9 months ago

I was trying to use transport and ngo at the same time, thinking they worked together fine but after starting ngo .Send gets intercepted by ngo or something and just breaks. I switched over to just sending packets with steam transport and I'm having a much better time than having a ton of issues with ngo

Pixel-Gamer commented 8 months ago

Hi, I seem to be having a similar issue aswell and was wondering how you got around it? What is the .Send that you are talking about and what exact "steam transport" are you talking about?

zanthous commented 8 months ago

it's something to use steam networking sockets with steamworks.net / unity multiplayer. I just send packets with the data I need and don't use any of the unity multplayer stuff