Giter Club home page Giter Club logo

multiplayer-community-contributions's Introduction

The Multiplayer Community Contributions repository contains extensions provided by the community for Unity Multiplayer Networking products.

How to use

Installing a Community Transport (Netcode for GameObjects)

Installing the Community Extensions Package (Netcode for GameObjects)

Community and Feedback

For general questions, networking advice or discussions about Unity Multiplayer Networking or Netcode for GameObjects, please join our Discord Community or create a post in the Unity Multiplayer Forum.

Maintenance

The contributions repository is a community repository and not an official Unity product. What this means is:

  • We will accept new content and bug fixes and try to keep the content in this repository up to date.
  • We do not guarantee that any of the content in this repository will be supported by future Netcode for GameObjects versions.
  • We ask the community and authors to maintain the content in this repository. Unity is not responsible for fixing bugs in community content.

Adding new content

Check our contribution guidelines for information on how to contribute to this repository.

Existing Content

Transports

Name Platforms 1.0.0 0.1.0 v12
Ruffles Desktop, Mobile ✔️ ✔️ ✔️
Enet Desktop, Mobile* ✔️ ✔️ ✔️
LiteNetLib Desktop, Mobile ✔️ ✔️ ✔️
SteamNetworkingSockets Steam ✔️ ✔️ ✔️
WebSocket Desktop, Mobile, WebGL ✔️ ✔️
Photon Realtime Desktop, Mobile, WebGL** ✔️ ✔️
Facepunch Steam ✔️ ✔️ ✔️
Multipeer Connectivity iOS ✔️ ✔️

* Needs manual binary compilation.
** Other platforms such as console platforms are also supported but require communication with Exit Games.

Extensions

Name 1.0.0 0.1.0 v12
LagCompensation ✔️ ✔️
NetworkObjectPool ✔️ ✔️
NetworkManagerHud ✔️ ✔️
NetworkDiscovery ✔️ ✔️
NetworkDictionary ✔️

Releases

Content for a specifc major version of Netcode for GameObjects can be found in the release branches. The following release branches exist:

Release
v12
0.1.0

multiplayer-community-contributions's People

Contributors

a7aate avatar andgeno avatar bigspaceships avatar cha-hoseong avatar copytime avatar cosmin-b avatar cyraid avatar davidyrgilbert avatar dmdemoura avatar fachryip avatar floris0106 avatar jaglitegrann avatar jamesmcghee avatar jesusluvsyooh avatar jpvanoosten avatar justonia avatar liamcary avatar lukestampfli avatar nullsoldier avatar puggsoy avatar qkdreyer avatar quantumsheep avatar simon-lemay-unity avatar sushiwaumai avatar thecaveofwonders avatar tobias-eg avatar twotenpvp avatar weinstein avatar whippetsaintdogs avatar yuchenz27 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

multiplayer-community-contributions's Issues

SteamP2P transport x86 crash

When building and running a steamp2p game on the Windows x86 platform and starting to host the game crashes. Switching to Windows x86_64 fixes it.

ENet Transport: Server should send shutdown event to connected clients before shutdown

Describe the bug
When server shuts down clients are not notified about this action going to happen and are left wondering what happened to the server. Connection on clients will time out after a while but this is an unnecessary condition.

Expected behavior
It would be better to send a notification to all connected clients before shutting down so everyone can shutdown gracefully.

Additional context
I used the latest ENet Transport build (commit: 5dc8f7b).

Steamworks issue with Linux editor

I had compile errors when opening the project on the Linux editor. I'm not 100% sure why. However, I have fixed the issue in my fork. You can see the commit if you're interested.
I'm reluctant to make a PR because it doesn't follow the original file structure that was there. I didn't really see a need to, I could basically just drag n drop the Steamworks.net Unity Package into the package folder and it all works fine. Confirmed on Windows, Mac, and Linux.

Just wanted to create the issue to either help anyone else that may run into this issue or to find out if a PR would be fine as well?

Compile Error on WebGL builds

JSWebSocketClient.cs:7

Please fix the namespace to Netcode.Transports.WebSocket and that should fix the compile error

What is the correct way to establish a connection for a custom transport

I am implementing a custom transport using iOS MultipeerConnectivity. I had a working version of old MLAPI, but now I am upgrading it to fit the new Netcode. I tried several ways to establish the connection and some of them worked, but I am sure what is the best way to do it and the logic behind it. I will explain how I am doing it currently:

Say we have two devices A and B, A is the host and B is a client, when they gets connected through MultipeerConnectivity

  1. On client B, return NetworkEvent.Connect in function PollEvent:
public override NetworkEvent PollEvent(out ulong clientId, out ArraySegment<byte> payload, out float receiveTime)
{
    if (m_NewPeerDidConnect)
    {
        m_NewPeerDidConnect = false;
        // The transportId of the host.
        clientId = m_NewPeerClientId;
        payload = new ArraySegment<byte>();
        receiveTime = Time.realtimeSinceStartup;
        return NetworkEvent.Connect;
    }
}

By doing above, Netcode will immediately send a connection request message to host A.

  1. When host A receives the connection request message, first return NetworkEvent.Connect in function PollEvent with client B's transportId and empty data payload, then for the same function, return NetworkEvent.Data with client B's transportId and the data payload sent along with the connection request message. By doing so, Netcode will send another message back to client B.

  2. When client B receives the message sent by the host at the end of step 2, the callback function NetworkManager.Singleton.OnClientConnectedCallback is called and it automatically sends another message to host A.

  3. When host A receives the message sent by the client at the end of step 3, it calls the same callback function NetworkManager.Singleton.OnClientConnectedCallback, and the bidirectional connection is finally established.

Is this the correct way to establish a connection? Is there a better way to do this?

I am currently encountering with this problem Unity-Technologies/com.unity.netcode.gameobjects#1431, I think probably a more proper way to establish the connection might solve it.

Thank you for finish reading this!

Output parameter 'payload' must be assigned before the function returns.

Here:

public override NetworkEvent PollEvent(out ulong clientId, out NetworkChannel channel, out ArraySegment<byte> payload, out float receiveTime)

And here:

public override NetworkEvent PollEvent(out ulong clientId, out NetworkChannel channel, out ArraySegment<byte> payload, out float receiveTime)

[SteamP2P] Coroutine couldn't be started error on application quit

When stop playing in Unity, MLAPI output following error:

Coroutine couldn't be started because the the game object 'NetworkManager' is inactive!
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
MLAPI.Transports.SteamP2P.SteamP2PTransport:Shutdown() (at Library/PackageCache/com.mlapi.contrib.transport.steamp2p@ea6c2d8db0/Runtime/SteamP2PTransport.cs:393)
MLAPI.NetworkManager:Shutdown() (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkManager.cs:632)
MLAPI.NetworkManager:OnDestroy() (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkManager.cs:596)

This happens in both Unity editor and builds and (seems to) causes the Steam connection not to be disconnected occasionally. If the player starts playing again and starts a host, a duplicated room hosted by the same player may happen.

Reproduce steps:

  1. Open any demo project with MLAPI and SteamP2P, e.g. this
  2. Start play in Unity editor
  3. Host a room
  4. Stop play in Unity editor

Environment:

  • Windows 10 19042.867 / macOS 11.2.3
  • Unity 2019.4.18f1
  • MLAPI 0.1.0 preview
  • SteamP2P Transport 1.0.0

WebGL build is broken with WebSocketTransport

It's not possible to build to WebGL if using WebSocketTransport

Exception: /home/raph/Unity/Hub/Editor/2019.4.16f1/Editor/Data/il2cpp/build/deploy/net471/UnityLinker.exe did not run properly!

Failed running "/home/raph/Unity/Hub/Editor/2019.4.16f1/Editor/Data/il2cpp/build/deploy/net471/UnityLinker.exe" @"/home/raph/Unity/IsWebSocketDead/Temp/StagingArea/Data/Managed/response.rsp" 

stdout:
Fatal error in Unity CIL Linker
Mono.Linker.MarkException: Error processing method: 'MLAPI.Transports.NetEventType WebSocketTransport.WebSocketTransport::PollEvent(System.UInt64&,System.String&,System.ArraySegment`1<System.Byte>&,System.Single&)' in assembly: 'WebSocketTransport.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.UInt64 MLAPI.WebSockets.WebSocketServerEvent::Id
  at Mono.Linker.Steps.MarkStep.HandleUnresolvedField (Mono.Cecil.FieldReference reference) [0x00018] in <c0c87e19439140b78d011a4c4a5bddd0>:0 
  at Mono.Linker.Steps.MarkStep.MarkField (Mono.Cecil.FieldReference reference) [0x0002d] in <c0c87e19439140b78d011a4c4a5bddd0>:0 
  at Mono.Linker.Steps.MarkStep.MarkInstruction (Mono.Cecil.Cil.Instruction instruction) [0x00044] in <c0c87e19439140b78d011a4c4a5bddd0>:0 
  at Mono.Linker.Steps.MarkStep.MarkMethodBody (Mono.Cecil.Cil.MethodBody body) [0x000e9] in <c0c87e19439140b78d011a4c4a5bddd0>:0 
  at Unity.Linker.Steps.UnityMarkStep.MarkMethodBody (Mono.Cecil.Cil.MethodBody body) [0x00001] in <8770b367edc74e678284d672346206ea>:0 
  at Mono.Linker.Steps.MarkStep.ProcessMethod (Mono.Cecil.MethodDefinition method) [0x001ca] in <c0c87e19439140b78d011a4c4a5bddd0>:0 
  at Unity.Linker.Steps.UnityMarkStep.ProcessMethod (Mono.Cecil.MethodDefinition method) [0x00041] in <8770b367edc74e678284d672346206ea>:0 
  at Mono.Linker.Steps.MarkStep.ProcessQueue () [0x00021] in <c0c87e19439140b78d011a4c4a5bddd0>:0 
   --- End of inner exception stack trace ---
  at Mono.Linker.Steps.MarkStep.ProcessQueue () [0x00052] in <c0c87e19439140b78d011a4c4a5bddd0>:0 
  at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue () [0x00019] in <c0c87e19439140b78d011a4c4a5bddd0>:0 
  at Mono.Linker.Steps.MarkStep.Process () [0x0013c] in <c0c87e19439140b78d011a4c4a5bddd0>:0 
  at Mono.Linker.Steps.MarkStep.Process (Mono.Linker.LinkContext context) [0x0000e] in <c0c87e19439140b78d011a4c4a5bddd0>:0 
  at Unity.Linker.Steps.UnityMarkStep.Process (Mono.Linker.LinkContext context) [0x00058] in <8770b367edc74e678284d672346206ea>:0 
  at Mono.Linker.Pipeline.ProcessStep (Mono.Linker.LinkContext context, Mono.Linker.Steps.IStep step) [0x0000e] in <c0c87e19439140b78d011a4c4a5bddd0>:0 
  at Unity.Linker.UnityPipeline.ProcessStep (Mono.Linker.LinkContext context, Mono.Linker.Steps.IStep step) [0x00018] in <8770b367edc74e678284d672346206ea>:0 
  at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x00014] in <c0c87e19439140b78d011a4c4a5bddd0>:0 
  at Unity.Linker.UnityDriver.Run () [0x0009b] in <8770b367edc74e678284d672346206ea>:0 
  at Unity.Linker.UnityDriver.RunDriverWithoutErrorHandling () [0x00007] in <8770b367edc74e678284d672346206ea>:0 
  at Unity.Linker.UnityDriver.RunDriver () [0x00002] in <8770b367edc74e678284d672346206ea>:0 
stderr:

UnityEditorInternal.Runner.RunProgram (UnityEditor.Utils.Program p, System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser) (at /home/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:126)
UnityEditorInternal.Runner.RunManagedProgram (System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser, System.Action`1[T] setupStartInfo) (at /home/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:71)
UnityEditorInternal.AssemblyStripper.RunAssemblyLinker (System.Collections.Generic.IEnumerable`1[T] args, System.String& out, System.String& err, System.String linkerPath, System.String workingDirectory) (at /home/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:168)
UnityEditorInternal.AssemblyStripper.StripAssembliesTo (System.String outputFolder, System.String& output, System.String& error, System.Collections.Generic.IEnumerable`1[T] linkXmlFiles, UnityEditorInternal.UnityLinkerRunInformation runInformation) (at /home/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:159)
UnityEditorInternal.AssemblyStripper.RunAssemblyStripper (UnityEditorInternal.UnityLinkerRunInformation runInformation) (at /home/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:303)
UnityEditorInternal.AssemblyStripper.StripAssemblies (System.String managedAssemblyFolderPath, UnityEditorInternal.BaseUnityLinkerPlatformProvider unityLinkerPlatformProvider, UnityEditorInternal.IIl2CppPlatformProvider il2cppPlatformProvider, UnityEditor.RuntimeClassRegistry rcr, UnityEditor.ManagedStrippingLevel managedStrippingLevel) (at /home/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:180)
UnityEditorInternal.IL2CPPBuilder.Run () (at /home/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:490)
UnityEditorInternal.IL2CPPUtils.RunIl2Cpp (System.String stagingAreaData, UnityEditorInternal.IIl2CppPlatformProvider platformProvider, System.Action`1[T] modifyOutputBeforeCompile, UnityEditor.RuntimeClassRegistry runtimeClassRegistry) (at /home/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:235)
UnityEditor.WebGL.WebGlBuildPostprocessor.CompileBuild (UnityEditor.Modules.BuildPostProcessArgs args) (at /Users/bokken/buildslave/unity/build/PlatformDependent/WebGL/Extensions/Unity.WebGL.extensions/BuildPostprocessor.cs:387)
UnityEditor.WebGL.WebGlBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at /Users/bokken/buildslave/unity/build/PlatformDependent/WebGL/Extensions/Unity.WebGL.extensions/BuildPostprocessor.cs:932)
UnityEditor.Modules.DefaultBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at /home/bokken/buildslave/unity/build/Editor/Mono/Modules/DefaultBuildPostprocessor.cs:29)
UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at /home/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:340)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at /home/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:197)

Steps to reproduce the behavior:

  1. Create a new 3D Project (Unity 2019.14.16)
  2. Import MLAPI with MLAPI-installer.unity
  3. Install MLAPI v11.11.4 (also tried with v12.1.7)+ WebSocketTransport (latest from the installer)
  4. Create a new NetworkingManager with WebSocket as transport
  5. Build to WebGL
  • OS: Archlinux (btw)
  • Unity Version: 2019.4
  • MLAPI Version: v11.11.4 and v.12.7
  • MLAPI Commit: [e.g. https://github.com/MidLevel/MLAPI/commit/c102935df1d7e0928283b48948fe96e5d96dd961]

Cannot checkout repository

I have tried to explore the Boss Room project, however I had a trouble when import the source file. Here is the error log:

An error occurred while resolving packages:
  Project has invalid dependencies:
    com.mlapi.contrib.transport.litenetlib: Cannot checkout repository [https://github.com/Unity-Technologies/mlapi-community-contributions.git] on target path [Transports/com.mlapi.contrib.transport.litenetlib]:
      Error when executing git command. fatal: cannot create directory at 'Transports/com.mlapi.contrib.transport.litenetlib/Runtime/LiteNetLib': No such file or directory

    com.mlapi.contrib.transport.photon-realtime: Cannot checkout repository [https://github.com/Unity-Technologies/mlapi-community-contributions.git] on target path [Transports/com.mlapi.contrib.transport.photon-realtime]:
      Error when executing git command. fatal: cannot create directory at 'Transports/com.mlapi.contrib.transport.photon-realtime/Runtime/Photon': No such file or directory

I would appreciate it if anyone could help me!

RufflesTransport DisconnectLocalClient not checking for null

When calling DisconnectLocalClient, there is no check if serverConnection is null. This results in an ArgumentException, e.g.

09-09 12:45:59.326 16539 16553 E Unity   : ArgumentException: Connection not alive
09-09 12:45:59.326 16539 16553 E Unity   :   at Ruffles.Core.RuffleSocket.Disconnect (Ruffles.Connections.Connection connection, System.Boolean sendMessage) [0x0000b] in <2570dab96a4b44398c60aa5c8256a797>:0
09-09 12:45:59.326 16539 16553 E Unity   :   at RufflesTransport.RufflesTransport.DisconnectLocalClient () [0x00001] in <10daec04849f4ec1b53089a464ab3308>:0
09-09 12:45:59.326 16539 16553 E Unity   :   at MLAPI.NetworkingManager.StopClient () [0x00019] in <0bb60a5cabe8428187ee2b0b9c2c6225>:0
09-09 12:45:59.326 16539 16553 E Unity   :   at MLAPI.NetworkingManager.HandleRawTransportPoll (MLAPI.Transports.NetEventType eventType, System.UInt64 clientId, System.String channelName, System.ArraySegment`1[T] payload, System.Single receiveTime) [0x00298] in <0bb60a5cabe8428187ee2b0b9c2c6225>:0
09-09 12:45:59.326 16539 16553 E Unity   :   at MLAPI.NetworkingManager.Update () [0x0005f] in <0bb60a5cabe8428187ee2b0b9c2c6225>:0

To reproduce, simply try connecting to a non existing server using Ruffles. Because of this exception, the StopClient method of the NetworkingManager is not run completely and therefore the transport is not cleared up (RufflesTransport.Shutdown not called). This prevents any reconnecting as a new call to RufflesTransport.GetConfig results in

09-09 12:46:00.299 16539 16553 E Unity   : ArgumentException: An item with the same key has already been added. Key: 0
09-09 12:46:00.299 16539 16553 E Unity   :   at System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) [0x000c1] in <a6266edc72ee4a578659208aefcdd5e1>:0
09-09 12:46:00.299 16539 16553 E Unity   :   at System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) [0x00000] in <a6266edc72ee4a578659208aefcdd5e1>:0
09-09 12:46:00.299 16539 16553 E Unity   :   at RufflesTransport.RufflesTransport.GetConfig () [0x00058] in <10daec04849f4ec1b53089a464ab3308>:0
09-09 12:46:00.299 16539 16553 E Unity   :   at RufflesTransport.RufflesTransport.StartClient () [0x00001] in <10daec04849f4ec1b53089a464ab3308>:0
09-09 12:46:00.299 16539 16553 E Unity   :   at MLAPI.NetworkingManager.StartClient () [0x00046] in <0bb60a5cabe8428187ee2b0b9c2c6225>:0

because channelIdToName was not cleared.

[Photon] `KeyNotFoundException: The given key '2' was not present in the dictionary` when collecting a client

I'm getting a KeyNotFoundException on the client-side shortly after running StartClient(). The exception is not happening with UNetTransport so I'm suspecting something to do with the PhotonRealtimeTransport.

Reproduction steps:

  1. Create an empty scene and add NetworkManager with PhotonRealtimeTransport.
  2. Add empty gameObject with a NetworkObject component and add as PlayerPrefab in NetworkManager
  3. Either create a build for the client or use ParrelSync.
  4. Start a Host then start a Client
  5. See the exception in the console. I've posted the full stack from below as well.

Details:
Unity Version: 2021.2.1f1
Netcode: 1.0.0-pre.3
Photon transport: 2.0.0 - commit hash: b32ffdd

[Exception] KeyNotFoundException: The given key '2' was not present in the dictionary.
System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item() at <c183552e59b24622ab6b4273bc2ea328>:0

NetworkManager.TransportIdToClientId() at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.3/Runtime/Core/NetworkManager.cs:1244
1242:   private ulong TransportIdToClientId(ulong transportId)
1243:   {
-->1244:       return transportId == m_ServerTransportId ? ServerClientId : m_TransportIdToClientIdMap[transportId];
1245:   }

NetworkManager.HandleRawTransportPoll() at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.3/Runtime/Core/NetworkManager.cs:1304
1302:   }
-->1304:   clientId = TransportIdToClientId(clientId);
1306:   HandleIncomingData(clientId, payload, receiveTime);

NetworkTransport.InvokeOnTransportEvent() at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.3/Runtime/Transports/NetworkTransport.cs:42
40:   protected void InvokeOnTransportEvent(NetworkEvent eventType, ulong clientId, ArraySegment<byte> payload, float receiveTime)
41:   {
-->42:       OnTransportEvent?.Invoke(eventType, clientId, payload, receiveTime);
43:   }

PhotonRealtimeTransport.InvokeTransportEvent() at Library/PackageCache/com.community.netcode.transport.photon-realtime@b32ffdd464/Runtime/PhotonRealtimeTransport.cs:407
405:           goto default;
406:       default:
-->407:           InvokeOnTransportEvent(networkEvent, senderId, payload, Time.realtimeSinceStartup);
408:           break;
409:   }

PhotonRealtimeTransport.OnEvent() at Library/PackageCache/com.community.netcode.transport.photon-realtime@b32ffdd464/Runtime/PhotonRealtimeTransport.cs:371
369:           reader.ReadBytesSafe(ref dataArray, length);
-->371:           InvokeTransportEvent(NetworkEvent.Data, senderId, new ArraySegment<byte>(dataArray, 0, dataArray.Length));
372:       }
373:   }

LoadBalancingClient.OnEvent() at Library/PackageCache/com.community.netcode.transport.photon-realtime@b32ffdd464/Runtime/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3335
3334:       this.UpdateCallbackTargets();
-->3335:       if (this.EventReceived != null) this.EventReceived(photonEvent);
3336:   }

PeerBase.DeserializeMessageAndCallback() at <1681fcfb2a274234971e611aa510f646>:0

EnetPeer.DispatchIncomingCommands() at <1681fcfb2a274234971e611aa510f646>:0

PhotonPeer.DispatchIncomingCommands() at <1681fcfb2a274234971e611aa510f646>:0

PhotonRealtimeTransport.Update() at Library/PackageCache/com.community.netcode.transport.photon-realtime@b32ffdd464/Runtime/PhotonRealtimeTransport.cs:105
103:       if (m_Client != null)
104:       {
-->105:           do { } while (m_Client.LoadBalancingPeer.DispatchIncomingCommands());
106:       }
107:   }

ENet Transport: Ungracefully disconnected clients stay as zombies on server

Describe the bug
If a client process is terminated (e.g. due to program crash) the server keeps the supposedly connected client in its list of connected clients -> zombie client.

To Reproduce

  • Start host
  • Connect client (in Unity Editor)
  • Stop the game for the client (in Unity Editor) or kill the game process somehow else
  • Client stays as zombie on server

Expected behavior
Client gets kicked from server after a time out.

Environment (please complete the following information):

  • OS: Windows 10
  • Unity Version: 2018.3.14f1
  • MLAPI Version: v10.3.0

Additional context
I used the latest ENet Transport build (commit: 97d3d1d).

In UNet this worked without any additional setup. I guess UNet must be sending a ping packet in the background to determine if a client has timed out.

NullReference when Network LogLevel == Developer

SteamP2PTransport.cs line 399 causes a NullReference when the LogLevel is set to Developer.
This is because NetworkManager.IsServer is not yet set to 'true' and therefore NetworkLog.LogServer tries to send the message over the network.

[Steamworks] Client show connected but nothing spawned.

Description

I'm trying to connect through Steam P2P as the listen-server and client, both host and client showing connected but nothing is spawning on the client, nor showing any log in the host that indicating a client is connected.

Host log:
host log

Client log:
client log

Repro Steps

  1. Download Space Shooter MLAPI.
  2. Make sure the Steam client app is running.
  3. (Host) Run Builds/ShooterSteamP2p.app (.exe) or in Editor, and click "Create Room".
  4. (Host) Host log should be shown as above.
  5. (Client) Run another build instance.
  6. (Client) Enter the steam ID (shown when host game), click "Join Room".
  7. (Client) Client log should be shown as above, but no player prefab is spawned nor any error.

Expected Behavior

Client connect successfully and the player prefab is spawned.
Host showing some log that a client is connected, client player prefab is spawned.

Environment:

  • macOS Catalina 10.15.6
  • Unity 2019.4.16f1
  • MLAPI 12.1.7

NetworkRigidbody Missing meta files

The NetworkRigidbody folder and its contents are missing their .meta files. Unity will therefore not allow them to be imported.

Stating:
"Asset Packages/com.mlapi.contrib.extensions/Runtime/NetworkRigidbody/NetworkRigidbody.cs has no meta file, but it's in an immutable folder. The asset will be ignored."

I assume the issue similar to
ef4d81d
"fix: Fix gitignore to include meta files"

Transport API has changed

Since latest update, Transport API has changed (NetworkCHannel removed and QoS introduced). All transports need update.

  • Photon :
  • LiteNetLib :
  • Ruffles : TODO
  • ENet : TODO
  • SteamP2P : TODO
  • WebSocket : TODO
  • FacePunch : TODO

Ruffles SocketError from StartClient

Using Ruffles, calling StartClient.Task.SocketError retults in a SocketError with no Task.Message. All Task states are false when this happen. The client is successful authorized and if I ignore this error and proceed I can play the game and all networking seems to work fine thereafter.

while (! startTask.Success) {
   Task.Yield();
   if (startTask.Tasks[0].SocketError != System.Net.Sockets.SocketError.Success || startTask.Tasks[0].TransportException != null) {
       break;     // If I ignore the error, everything works still
       //return;  // But no way to report a real StartClient error as before
       }
   }

I'd normally return from an error, informing the user. This is what I did with uNet. But now with Ruffles and this possibly invalid SocketError I can't know the difference.
I think this is a Ruffles bug.
What can I do to help resolve it?

Unity 2019.3.0f1 MLAPI 11.10.0 Ruffles latest

NullReferenceException when using SteamP2P Transport

I am using the SteamP2P Transport and have a simple setup for a lobby in unity. When trying to join a hosted game as a client, after a few seconds a NullReferenceException gets thrown in the NetworkManager.cs, at line 1144:
MessagingSystem.ProcessIncomingMessageQueue();

Then the NetworkManager.Singleton.OnClientDisconnectCallback is called, against what the NetworkManager.Singleton.OnClientConnectedCallback never gets called (so the client never connects properly).

Here are two threads, where people describe the similar problems:

  1. https://answers.unity.com/questions/1869491/messagingsystemprocessincomingmessagequeue-nullref.html?childToView=1870613
  2. forum.unity.com/threads/anyone-have-sample-mlapi-with-steam-matchmaking.1098304/

I am using:

  • Unity 2020.3.20f1
  • Netcode for GameObjects 1.0.0-pre.3
  • Multiplayer Tools 1.0.0-pre.2
  • SteamP2P Transport for Netcode for GameObjects 2.0.0

ENet Unity Editor Usability Issues with Channel & Flags

When creating channels in the Unity editor for the ENet transport, the Flags field does not allow for multiple PacketFlags values to be selected.

In order for an enum of flags to be used properly in the editor and allow for multiple values to be selected, a custom property drawer needs to be created. EditorGUILayout.EnumFlagsField can be used in the property drawer to easily render the flags enum appropriately when tagged with the property drawer's attribute. Examples of complete property drawer code for displaying flags enums in the editor can be found easily online.

Either that, or a List<PacketFlags> could be used in editor, and combined together into one value on Init(). However, that would require creating another class or struct to represent the data in the editor, separate from the one used to represent the channels at runtime which seems messy in its own way. But, it does not require creating a custom property drawer.

Looking at the ENet PacketFlags, and without being an expert in the native functionality of ENet-CSharp, I wonder if the NoAllocate flag has any valid use case in this context as a transport for MLAPI. Also, if you have a working flags drawer, and a novice user just selects all of the flags some of them seem contradictory. I imagine that those cases are handled in the native ENet code with some kind of priority to the flags, but the intended behavior may be unpredictable at the level of MLAPI in the Unity editor.

Also, the Id field of EnetChannel is serialized in the editor, but the value specified by the user has no functionality, which is confusing to the user. The Id value is defined automatically and used by the internalChannels after Init(), but it need not be serialized or displayed in the editor. Setting it to be a property instead of a field is an easy way to prevent it from being serialized without changing any other functionality.

Perhaps instead of Channels being a List<EnetChannel> it should be a List<TransportChannel> and the same code applied to MLAPI_CHANNELS in MLAPIChannelTypeToPacketFlag() should be applied to internal channels specified by the user.

[Steamworks] Steam Networking Sockets

Hi, Old P2P in Steamworks will be removed soon and will be replaced with Steam Networking Sockets. Please let me know! Steamworks transport is using steam networking sockets? if not, can you update with SteamNetworkingSockets? or anyone has this function please share this with me. Thank you

Enet transport lacks a Peers Clear inside Shutdown

In Transports/com.mlapi.contrib.transport.enet/Runtime/EnetTransport.cs
Shutdown() at Line 341 :
Add a : connectedEnetPeers?.Clear();

Otherwise it won't be cleared when a connection mis-approval shutdowns client and Add Errors....

LiteNetLibTransport : Closing Unity editor spits out error

Describe the bug
When stopping the Unity editor and you are using the LiteNetLibTransport on your NetworkingManager it gives an error message

To Reproduce
Steps to reproduce the behavior:

  1. Create a sample scene with a networking manager and default settings
  2. Change the Transport to be the LiteNetLibTransport
  3. Start the Unity editor then stop it
  4. See error

Expected behavior
It's supposed to not give an error

Screenshots
image

Environment (please complete the following information):

  • OS: Windows 10
  • Unity Version: 2020.1.0b5
  • MLAPI Version: 11.11.0

NetworkDiscovery generates errors on write "OverflowException: Attempted to write without first calling TryBeginWrite()"

OverflowException: Attempted to write without first calling TryBeginWrite()
NetworkDiscovery2[TBroadCast,TResponse].WriteHeader (Unity.Netcode.FastBufferWriter writer, NetworkDiscovery2+MessageType[TBroadCast,TResponse] messageType) (at Library/PackageCache/com.community.netcode.extensions@af696175c6/Runtime/NetworkDiscovery/NetworkDiscovery.cs:240)
NetworkDiscovery`2[TBroadCast,TResponse].ClientBroadcast (TBroadCast broadCast) (at Library/PackageCache/com.community.netcode.extensions@af696175c6/Runtime/NetworkDiscovery/NetworkDiscovery.cs:71)
ExampleNetworkDiscoveryHud.ClientSearchGUI () (at Library/PackageCache/com.community.netcode.extensions@af696175c6/Runtime/NetworkDiscovery/ExampleNetworkDiscoveryHud.cs:101)
ExampleNetworkDiscoveryHud.OnGUI () (at Library/PackageCache/com.community.netcode.extensions@af696175c6/Runtime/NetworkDiscovery/ExampleNetworkDiscoveryHud.cs:62)

[Steamworks] Steam API Init failed in the latest 1.0.0 SteamP2P transport

It is nice to see Steamworks.NET is included in the SteamP2P transport so we don't need more setup, but it couldn't initialize at all and I'm sure I did have all settings correctly (having the steam_appid.txt in the project root, etc)

[Steamworks.NET] SteamAPI_Init() failed. Refer to Valve's documentation or the comment above this line for more information.
UnityEngine.Debug:LogError(Object, Object)
SteamManager:Awake() (at Library/PackageCache/com.mlapi.contrib.transport.steamp2p@3f0350ae57/Runtime/SteamManager.cs:120)
UnityEngine.GameObject:AddComponent()
SteamManager:get_Instance() (at Library/PackageCache/com.mlapi.contrib.transport.steamp2p@3f0350ae57/Runtime/SteamManager.cs:31)
SteamManager:get_Initialized() (at Library/PackageCache/com.mlapi.contrib.transport.steamp2p@3f0350ae57/Runtime/SteamManager.cs:42)

It was totally fine in the old 12.x version. Currently, a workaround is using the official Steamworks.NET instead of the one provided by the transport.

Environment:
Windows 10 19042.867
Unity 2019.4.18f1
MLAPI 0.1.0 preview
SteamP2P Transport 1.0.0

ISteamNetworking is deprecated

Hi there - I notice MLAPI.Transports.SteamP2P uses the deprecated ISteamNetwork API. This API is flagged as deprecated and may be removed:

https://partner.steamgames.com/doc/api/ISteamNetworking
NOTE: This API is deprecated and may be removed in a future Steamworks SDK release. Please use ISteamNetworkingSockets or ISteamNetworkingMessages instead. See the Steam Networking overview for more information.

Are there any plans to update this? I'm completely new to these APIs or I would offer to have a crack at it.

GC allocation using Ruffles as Transport for MLAPI

The use case is similar to the issue described here for the MLAPI.

Environment:
OS: Windows 10
Unity Version: 2019.1
MLAPI Version: latest
MLAPI Commit: latest
Ruffles Commit: latest

Using Ruffles as the Transport for the MLAPI library 20 moving elements are updating their position from the server to all clients at 20Hz. The client is experiencing very low framerates due to garbage allocation and subsequent calls to garbage collector.
In the RuffleTransport.cs script when creating the SocketConfig class a line has been added to disable all verbose logs via the newly provided field (config.UseVerboseInfoLogging = false).

Compared to the garbage allocation described in this issue it has considerably been reduced thanks to the prevention of all the string related calls. However there are still quite some allocations all derived from the function RufflesSocket.InternalPollSocket() which is called multiple times per frame, ranging from 13 up to 73 calls. Each call is allocating 474B which for example when invoked 73 times 33.7KB of garbage as higlighted in the figure below.
Inside this call the two main methods causing allocation are Socket.ReceiveFrom() and RuffleSocket.HandlePacket(). In the below image the former is allocating 24.1kB and the latter is allocating 9.6kB.

image

Below there is a long list of images with highlighted all allocation calls from the two methods mentioned earlier. Here you can also find attached the profiler sampled data to load into the unity profiler.

Hope this infomation is of any help.

regards,

Francesco

from: Socket.ReceiveFrom()

image

image

image

image

image

image

from: RuffleSocket.HandlePacket()

image

image

transport.websocket (wss) JSWebSocketClient.Connect() opening handshake is timing out

Related Unity Thread: https://forum.unity.com/threads/webgl-websocket-troubleshooting.1185469/

I'm having trouble getting HTTPS (wss) connections to work, HTTP (ws) works fine.

It looks like after JSWebSocketClient.Connect() is called, it never completes the handshake. I'm running a Windows instance of the application (host), and I'm also running a WebGL instance of the application on a site as the client. I enter in the port and IP for the client to connect too and the handshake times out. If I untick the secure connection, it works. Are there certain certificates that I'm missing? I can provide more information if needed.

RufflesTransport using UTC while Ruffles uses local time

When calculating the receiveTime in RufflesTransport: https://github.com/MidLevel/MLAPI.Transports/blob/d03b1a15e3561fe80b854acfd8de8c6ac92e3312/RufflesTransport/RufflesTransport.cs#L61 it uses Utc time. However, for @event.SocketReceiveTime Ruffles uses local time (e.g.
https://github.com/MidLevel/Ruffles/blob/fd4a9fd9f907cb3affeb20828418bb23ea3d00c5/Ruffles/Core/RuffleSocket.cs#L571)

With my timezone GMT+2 this results in a negative NetworkTime

[Feature Request] Steam P2P through Facepunch.Steamworks

I would like to have the option to use Facepunch for interfacing with steam and for networking. It should be quite easy as the only difference between this and the already existing steamp2ptransport is the backend layer. Also, Facepunch is a much more user friendly interface for steam in my experience.

Photon exception on client after disconnect event

Describe the bug
After getting disconnected from photon, the client sometimes develops an exception that fires every frame. This bug is a complement to bug Unity-Technologies/com.unity.netcode.gameobjects#823. It isn't wrong that the client gets disconnected (although the timeout of only a few seconds is pretty aggressive). But it seems that the PhotonRealtimeTransport is in a bad state after the shutdown, and generates exceptions.

To Reproduce

  1. Open the BossRoom demo in editor. Window->Photon Realtime->Highlight Server Settings.
  2. Put in your own personal appid from photonengine.com
  3. Start the game in a separate built client, select "Start", and then "Relay Host".
  4. Start the game in editor, select "Join", "Relay Host", and the room name.
  5. Once both host and client are in character select, pick character and enter the game.
  6. Walk around with the joiner client and pick a fight with an imp (I think having some active network traffic is helpful in getting the exception).
  7. Pull your network cable. Count to 5, then plug it back in.
  8. Observe that sometimes (around 50% of the time), after you are returned to main menu, you get a continuous stream of exceptions from the PhotonRealtimeTransport

Actual outcome
An exception gets thrown every frame after a client gets disconnected from the Photon Relay Server.

Expected outcome
No exceptions are generated.

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS: [e.g. Windows 10]
  • Unity Version: [e.g. 2019.1]
  • MLAPI Version: [e.g. v6.0.1]
  • MLAPI Commit: [e.g. https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/commit/c102935df1d7e0928283b48948fe96e5d96dd961]

Additional context

callstack of the Exception. m_Client is null, which is no surprise, since NetworkManager has already been Shutdown by this point.

Int32 MLAPI.Transports.PhotonRealtime.PhotonRealtimeTransport:get_CurrentMasterId ()+0x0 at C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.mlapi.contrib.transport.photon-realtime@3f0350ae57\Runtime\PhotonRealtimeTransport.Matchmaking.cs:[15:34-15:115]	C#
Int32 MLAPI.Transports.PhotonRealtime.PhotonRealtimeTransport:GetPhotonRealtimeId (UInt64)+0xc at C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.mlapi.contrib.transport.photon-realtime@3f0350ae57\Runtime\PhotonRealtimeTransport.cs:[472:17-472:40]	C#
Void MLAPI.Transports.PhotonRealtime.PhotonRealtimeTransport:RaisePhotonEvent (UInt64, Boolean, ArraySegment`1, Byte)+0xf at C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.mlapi.contrib.transport.photon-realtime@3f0350ae57\Runtime\PhotonRealtimeTransport.cs:[245:13-245:87]	C#
Void MLAPI.Transports.PhotonRealtime.PhotonRealtimeTransport:FlushAllSendQueues ()+0x58 at C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.mlapi.contrib.transport.photon-realtime@3f0350ae57\Runtime\PhotonRealtimeTransport.cs:[231:17-231:113]	C#

Void MLAPI.Transports.PhotonRealtime.PhotonRealtimeTransport:LateUpdate ()+0x2 at C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.mlapi.contrib.transport.photon-realtime@3f0350a\Runtime\PhotonRealtimeTransport.cs:[114:13-114:34] C#

This is the callstack showing the network shutdown the client gets, triggered by a Disconnect event from the Photon relay server.

Void MLAPI.NetworkManager:Shutdown ()+0x1 at C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.unity.multiplayer.mlapi@3e3aef6aa0\Runtime\Core\NetworkManager.cs:[603:13-603:66]	C#
Void MLAPI.NetworkManager:StopClient ()+0x3d at C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.unity.multiplayer.mlapi@3e3aef6aa0\Runtime\Core\NetworkManager.cs:[512:13-512:24]	C#
Void MLAPI.NetworkManager:HandleRawTransportPoll (NetworkEvent, UInt64, NetworkChannel, ArraySegment`1, Single)+0x182 at C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.unity.multiplayer.mlapi@3e3aef6aa0\Runtime\Core\NetworkManager.cs:[895:25-895:38]	C#
Void MLAPI.Transports.NetworkTransport:InvokeOnTransportEvent (NetworkEvent, UInt64, NetworkChannel, ArraySegment`1, Single)+0x14 at C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.unity.multiplayer.mlapi@3e3aef6aa0\Runtime\Transports\NetworkTransport.cs:[123:13-123:92]	C#

Void MLAPI.Transports.PhotonRealtime.PhotonRealtimeTransport:InvokeTransportEvent (NetworkEvent, UInt64, NetworkChannel, ArraySegment`1)+0x41 at C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.mlapi.contrib.transport.photon-realtime@3f0350a\Runtime\PhotonRealtimeTransport.cs:[424:21-424:113] C#
Void MLAPI.Transports.PhotonRealtime.PhotonRealtimeTransport:OnPlayerLeftRoom (Player)+0x3c at C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.mlapi.contrib.transport.photon-realtime@3f0350a\Runtime\PhotonRealtimeTransport.Room.cs:[48:17-48:58] C#
Void Photon.Realtime.InRoomCallbacksContainer:OnPlayerLeftRoom (Player)+0x22 at C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.mlapi.contrib.transport.photon-realtime@3f0350a\Runtime\Photon\PhotonRealtime\Code\LoadBalancingClient.cs:[4184:17-4184:54] C#
Void Photon.Realtime.LoadBalancingClient:OnEvent (EventData)+0x2d5 at C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.mlapi.contrib.transport.photon-realtime@3f0350a\Runtime\Photon\PhotonRealtime\Code\LoadBalancingClient.cs:[3197:21-3197:84] C#
Boolean ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback (StreamBuffer)+0x2e9 at :-1 C#
Boolean ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands ()+0x3b6 at :-1 C#
Boolean ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands ()+0x3a at :-1 C#
Void MLAPI.Transports.PhotonRealtime.PhotonRealtimeTransport:Update ()+0x1c at C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.mlapi.contrib.transport.photon-realtime@3f0350a\Runtime\PhotonRealtimeTransport.cs:[105:24-105:86] C#

Photon exception in extreme network conditions

Describe the bug
In some extreme network conditions, the Host's PhotonRelayTransport will crash while flushing send queues in LateUpdate. From initial inspection, this seems like it might be related to issue #70 , where the PhotonRealtimeTransport is continuing to run even after its m_Client field has gone null.

The attached exception comes from a network test with the following settings: bandwidth cap: 3 KB/s, Loss Rate: 25%, latency: natural latency (~50ms RTT). NetLimiter was used to do the testing.

To Reproduce

  1. Launch the latest version of Boss Room, Develop Branch. connect with at least 2 clients.
  2. Create one of the limited network environments described (such as: capped game bandwidth to 3 kb/s, with a 25% data drop rate and 250 ms of latency) on the host machine.
  3. Play the game for a short while. eventually the host will crash (and the clients will of course lose contact).

Actual outcome
Host starts throwing exceptions in extreme network conditions.

Expected outcome
Host starts dropping connections until its send queues stop backing up. Alternately, MLAPI could raise an event and let the Application decide what to do.

Environment (please complete the following information):

  • OS: e.g. Windows 10
  • Unity Version: 2020.3.6f1
  • MLAPI Version: v0.1.0
  • MLAPI Commit: release/v0.1.0

Additional context

NullReferenceException: Object reference not set to an instance of an object
at MLAPI.Transports.PhotonRealtime.PhotonRealtimeTransport.RaisePhotonEvent (System.UInt64 clientId, System.Boolean isReliable, System.ArraySegment`1[T] data, System.Byte eventCode) [0x00025] in C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.mlapi.contrib.transport.photon-realtime@3f0350a\Runtime\PhotonRealtimeTransport.cs:249
at MLAPI.Transports.PhotonRealtime.PhotonRealtimeTransport.FlushAllSendQueues () [0x00038] in C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.mlapi.contrib.transport.photon-realtime@3f0350a\Runtime\PhotonRealtimeTransport.cs:231
at MLAPI.Transports.PhotonRealtime.PhotonRealtimeTransport.LateUpdate () [0x00001] in C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.mlapi.contrib.transport.photon-realtime@3f0350a\Runtime\PhotonRealtimeTransport.cs:114

(Filename: C:/dev/com.unity.multiplayer.samples.coop/Library/PackageCache/com.mlapi.contrib.transport.photon-realtime@3f0350a/Runtime/PhotonRealtimeTransport.cs Line: 249)

Number of errors when implementing new transport

Hi there, I'm getting a number of MLAPI errors while building a SteamNetworkingSockets transport and I'd love some help.

The transport appears to be partially working. The host sometimes doesn't display one or the other player, and sometimes players lag badly. Seems to be luck of the draw.

I have a feeling I'm doing something like leaving old data in the send and receive buffers between events but I don't know enough about buffers in c# to intuit the answer.

Buffers are created like so, taken verbatim from rlabrecque/Steamworks.NET#411 (comment):

     IntPtr sendBuffer = Marshal.AllocHGlobal(65536);
     IntPtr[] receiveBuffers = new IntPtr[1]; // given PollEvent returns a single NetworkEvent, it seems we can only handle one message at a time.

The relevant Send code:

    public override void Send(ulong clientId, ArraySegment<byte> data, NetworkChannel channel)
    {
      int nSendFlags = ChannelSendFlags[channel];
      HSteamNetConnection sendToHConn = isServer ? steamIdToHConn[clientId] : serverHConn;

      Debug.Log($"Send(clientId {clientId}, data {data}, channel {channel});");

      try
      {
        Marshal.Copy(data.Array, 0, sendBuffer, data.Array.Length);
        SteamNetworkingSockets.SendMessageToConnection(sendToHConn, sendBuffer, (uint)data.Array.Length, nSendFlags, out _);
      }
      catch
      {
        Marshal.FreeHGlobal(sendBuffer);
      }
    }

The relevant PollEvent code:

      // if there are no messages, return
      if (messageCount > 0)
      {
        Debug.Log($"PollEvent(); // messageCount is {messageCount}");
        try
        {
          SteamNetworkingMessage_t netMessage = Marshal.PtrToStructure<SteamNetworkingMessage_t>(receiveBuffers[0]);
          byte[] message = new byte[netMessage.m_cbSize];
          Marshal.Copy(netMessage.m_pData, message, 0, message.Length);

          payload = new ArraySegment<byte>(message);
          clientId = netMessage.m_identityPeer.GetSteamID64();

          Debug.Log($"PollEvent(); // message received at {receiveTime} from {clientId}");

          SteamAPI_SteamNetworkingMessage_t_Release(receiveBuffers[0]);
        }
        finally
        {
          Marshal.DestroyStructure<SteamNetworkingMessage_t>(receiveBuffers[0]);
        }
        return NetworkEvent.Data;
      }

Any guidance on how to fix this would be appreciated.

These errors are occasionally appearing in both consoles:

OSXPlayer(Alices-MacBook-Air.local) RpcQueueContainer 65 update type does not exist!
UnityEngine.StackTraceUtility:ExtractStackTrace () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/StackTrace.cs:37)
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
UnityEngine.Logger:Log (UnityEngine.LogType,object)
UnityEngine.Debug:LogError (object)
MLAPI.Messaging.RpcQueueContainer:GetQueueHistoryFrame (MLAPI.Messaging.RpcQueueHistoryFrame/QueueFrameType,MLAPI.NetworkUpdateStage,bool) (at /Users/wgodfrey/code/unity/learning/MLAPI 03/Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Messaging/RpcQueue/RpcQueueContainer.cs:567)
MLAPI.Messaging.RpcQueueContainer:AddQueueItemToInboundFrame (MLAPI.Messaging.RpcQueueContainer/QueueItemType,single,ulong,MLAPI.Serialization.NetworkBuffer) (at /Users/wgodfrey/code/unity/learning/MLAPI 03/Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Messaging/RpcQueue/RpcQueueContainer.cs:284)
MLAPI.Messaging.InternalMessageHandler:RpcReceiveQueueItem (ulong,System.IO.Stream,single,MLAPI.Messaging.RpcQueueContainer/QueueItemType) (at /Users/wgodfrey/code/unity/learning/MLAPI 03/Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Messaging/InternalMessageHandler.cs:568)
MLAPI.NetworkManager:ReceiveCallback (MLAPI.Serialization.NetworkBuffer,MLAPI.Messaging.RpcQueueContainer/QueueItemType,ulong,single) (at /Users/wgodfrey/code/unity/learning/MLAPI 03/Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkManager.cs:1094)
MLAPI.Messaging.RpcBatcher:ReceiveItems (MLAPI.Serialization.NetworkBuffer&,MLAPI.Messaging.RpcBatcher/ReceiveCallbackType,MLAPI.Messaging.RpcQueueContainer/QueueItemType,ulong,single) (at /Users/wgodfrey/code/unity/learning/MLAPI 03/Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Messaging/RpcBatcher.cs:216)
MLAPI.NetworkManager:HandleIncomingData (ulong,MLAPI.Transports.NetworkChannel,System.ArraySegment`1<byte>,single,bool) (at /Users/wgodfrey/code/unity/learning/MLAPI 03/Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkManager.cs:1060)
MLAPI.NetworkManager:HandleRawTransportPoll (MLAPI.Transports.NetworkEvent,ulong,MLAPI.Transports.NetworkChannel,System.ArraySegment`1<byte>,single) (at /Users/wgodfrey/code/unity/learning/MLAPI 03/Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkManager.cs:875)
MLAPI.NetworkManager:OnNetworkEarlyUpdate () (at /Users/wgodfrey/code/unity/learning/MLAPI 03/Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkManager.cs:683)
MLAPI.NetworkManager:NetworkUpdate (MLAPI.NetworkUpdateStage) (at /Users/wgodfrey/code/unity/learning/MLAPI 03/Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkManager.cs:641)
MLAPI.NetworkUpdateLoop:RunNetworkUpdateStage (MLAPI.NetworkUpdateStage) (at /Users/wgodfrey/code/unity/learning/MLAPI 03/Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkUpdateLoop.cs:148)
MLAPI.NetworkUpdateLoop/NetworkEarlyUpdate/<>c:<CreateLoopSystem>b__0_0 () (at /Users/wgodfrey/code/unity/learning/MLAPI 03/Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkUpdateLoop.cs:171)

(Filename: /Users/wgodfrey/code/unity/learning/MLAPI 03/Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Messaging/RpcQueue/RpcQueueContainer.cs Line: 567)

The number 65 is different every time. Always a uint8, so seems to be a byte out of place.

This one is caused by the last one:

OSXPlayer(Alices-MacBook-Air.local) NullReferenceException: Object reference not set to an instance of an object
  at MLAPI.Messaging.RpcQueueContainer.AddQueueItemToInboundFrame (MLAPI.Messaging.RpcQueueContainer+QueueItemType qItemType, System.Single timeStamp, System.UInt64 sourceNetworkId, MLAPI.Serialization.NetworkBuffer message) [0x00050] in /Users/wgodfrey/code/unity/learning/MLAPI 03/Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Messaging/RpcQueue/RpcQueueContainer.cs:285 
  at MLAPI.Messaging.InternalMessageHandler.RpcReceiveQueueItem (System.UInt64 clientId, System.IO.Stream stream, System.Single receiveTime, MLAPI.Messaging.RpcQueueContainer+QueueItemType queueItemType) [0x00073] in /Users/wgodfrey/code/unity/learning/MLAPI 03/Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Messaging/InternalMessageHandler.cs:568 

And finally

ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
System.Buffer.BlockCopy (System.Array src, System.Int32 srcOffset, System.Array dst, System.Int32 dstOffset, System.Int32 count) (at <695d1cc93cca45069c528c15c9fdd749>:0)
MLAPI.Messaging.RpcBatcher.ReceiveItems (MLAPI.Serialization.NetworkBuffer& messageBuffer, MLAPI.Messaging.RpcBatcher+ReceiveCallbackType receiveCallback, MLAPI.Messaging.RpcQueueContainer+QueueItemType messageType, System.UInt64 clientId, System.Single receiveTime) (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Messaging/RpcBatcher.cs:214)
MLAPI.NetworkManager.HandleIncomingData (System.UInt64 clientId, MLAPI.Transports.NetworkChannel networkChannel, System.ArraySegment`1[T] data, System.Single receiveTime, System.Boolean allowBuffer) (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkManager.cs:1042)
MLAPI.NetworkManager.HandleRawTransportPoll (MLAPI.Transports.NetworkEvent networkEvent, System.UInt64 clientId, MLAPI.Transports.NetworkChannel networkChannel, System.ArraySegment`1[T] payload, System.Single receiveTime) (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkManager.cs:875)
MLAPI.NetworkManager.OnNetworkEarlyUpdate () (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkManager.cs:683)
MLAPI.NetworkManager.NetworkUpdate (MLAPI.NetworkUpdateStage updateStage) (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkManager.cs:641)
MLAPI.NetworkUpdateLoop.RunNetworkUpdateStage (MLAPI.NetworkUpdateStage updateStage) (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkUpdateLoop.cs:148)
MLAPI.NetworkUpdateLoop+NetworkEarlyUpdate+<>c.<CreateLoopSystem>b__0_0 () (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkUpdateLoop.cs:171)

NetworkDiscovery generates errors on write "OverflowException: Attempted to write without first calling TryBeginWrite()"

I just imported the Extension package because I wanted to try the discovery.
I added the 2 examples to my NetworkManager GameObject and tried to start unity.
it then proceeded to log this error everytime a broadcast is supposed to be sent:

OverflowException: Attempted to write without first calling TryBeginWrite()
NetworkDiscovery`2[TBroadCast,TResponse].WriteHeader (Unity.Netcode.FastBufferWriter writer, NetworkDiscovery`2+MessageType[TBroadCast,TResponse] messageType) (at Library/PackageCache/com.community.netcode.extensions@b08829c71c/Runtime/NetworkDiscovery/NetworkDiscovery.cs:240)
NetworkDiscovery`2[TBroadCast,TResponse].ClientBroadcast (TBroadCast broadCast) (at Library/PackageCache/com.community.netcode.extensions@b08829c71c/Runtime/NetworkDiscovery/NetworkDiscovery.cs:71)
ExampleNetworkDiscoveryHud.ClientSearchGUI () (at Library/PackageCache/com.community.netcode.extensions@b08829c71c/Runtime/NetworkDiscovery/ExampleNetworkDiscoveryHud.cs:101)
ExampleNetworkDiscoveryHud.OnGUI () (at Library/PackageCache/com.community.netcode.extensions@b08829c71c/Runtime/NetworkDiscovery/ExampleNetworkDiscoveryHud.cs:62)

I am using:
Unity 2020.1.23f1
Netcode for Gameobjects 1.0.0-pre.2
Unity Transport 1.0.0-pre.6
Unity Transport for Netcode for GameObjects 1.0.0-pre.2
Netcode for GameObjects Community Extensions Package 1.0.0

SteamP2P Building fails.

Building the SteamP2P transport fails because there are multiple dlls in the package and they don't target the right build platforms.

Facepunch Steamworks Socket Transport Build error

ReadOnlyAttribute.cs is giving buld errors.

error CS0246: The type or namespace name 'PropertyAttribute' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'CustomPropertyDrawer' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'PropertyDrawer' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'ReadOnlyDrawer' could not be found (are you missing a using directive or an assembly reference?)

Deleting the entire script and its references in FacepunchTransport.cs has resolved the issue temporarily for me until a fix is made.

NetworkRigidbody client writing in NetworkVariable without authorisation exception when connecting to a server

I simply added some NetworkRigidbody in the scene, when I connect to a server, I get an exception :

[MLAPI] Client wrote to NetworkVariable without permission. No more variables can be read. This is critical
image

For each one in the scene.

It concerns one of the NetworkVariableVector3 variable (netVelocity, netAngularVelocity or netPosition) because I have as many messages like this as the previous error message
image

I don't know how MLAPI handles the NetworkVariable but I changed the order of declaration like this :
image
And it still crashes on NetworkVariableVector3. I was expecting that it would crash on NetworkVariableQuaternion.
But maybe the order by which it accesses NetworkVariable has nothing to do with their order in the class. But in the other case, the issue could be related specificaly to NetworkVariableVector3...

For now, the only way I found to make the exception disapear is to add a return as the first instruction in the FixedUpdate. Which is quite inadequate. To say the least.

I didn't modify the script whatsoever.
The only interaction I have with it is enabling and disabling it given some conditions.

Have you any idea on why this could happen ?

Photon Transport NullReferenceException

Describe the bug
A NullReferenceException occurred on the client when I disconnected both it and the host from the network simultaneously.

To Reproduce
Steps to reproduce the behavior:

  1. Configure the BossRoom network demo to use the Photon transport library.
  2. Start a host and client, connected via the Photon Relay.
  3. Pull your network cable.
  4. Observe that the client is kicked to main menu (correctly), but that this NRE starts spewing:

NullReferenceException: Object reference not set to an instance of an object
at MLAPI.Transports.PhotonRealtime.PhotonRealtimeTransport.get_CurrentMasterId () [0x00000] in C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.mlapi.contrib.transport.photon-realtime@3f0350a\Runtime\PhotonRealtimeTransport.Matchmaking.cs:15
at MLAPI.Transports.PhotonRealtime.PhotonRealtimeTransport.GetPhotonRealtimeId (System.UInt64 clientId) [0x0000b] in C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.mlapi.contrib.transport.photon-realtime@3f0350a\Runtime\PhotonRealtimeTransport.cs:472
at MLAPI.Transports.PhotonRealtime.PhotonRealtimeTransport.RaisePhotonEvent (System.UInt64 clientId, System.Boolean isReliable, System.ArraySegment`1[T] data, System.Byte eventCode) [0x00001] in C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.mlapi.contrib.transport.photon-realtime@3f0350a\Runtime\PhotonRealtimeTransport.cs:245
at MLAPI.Transports.PhotonRealtime.PhotonRealtimeTransport.FlushAllSendQueues () [0x00038] in C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.mlapi.contrib.transport.photon-realtime@3f0350a\Runtime\PhotonRealtimeTransport.cs:231
at MLAPI.Transports.PhotonRealtime.PhotonRealtimeTransport.LateUpdate () [0x00001] in C:\dev\com.unity.multiplayer.samples.coop\Library\PackageCache\com.mlapi.contrib.transport.photon-realtime@3f0350a\Runtime\PhotonRealtimeTransport.cs:114

(Filename: C:/dev/com.unity.multiplayer.samples.coop/Library/PackageCache/com.mlapi.contrib.transport.photon-realtime@3f0350a/Runtime/PhotonRealtimeTransport.Matchmaking.cs Line: 15)

Actual outcome
exception occurred on disconnect.

Expected outcome
client is disconnected to main menu, and no error appears.

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS: [e.g. Windows 10]
  • Unity Version: [e.g. 2019.1]
  • MLAPI Version: [e.g. v6.0.1]
  • MLAPI Commit: [e.g. https://github.com/Unity-Technologies/com.unity.multiplayer.mlapi/commit/c102935df1d7e0928283b48948fe96e5d96dd961]

Additional context
Add any other context about the problem here. Logs, code snippets would be useful here but please also consider attaching a minimal Unity project that reproduces the issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.