Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

WebGL Builds + Netcode?

Discussion in 'Netcode for GameObjects' started by Brian-Kryptomon, Jul 19, 2022.

  1. Brian-Kryptomon

    Brian-Kryptomon

    Joined:
    Apr 17, 2022
    Posts:
    15
    Has anyone been able to get this to successfully work?

    There was a bug that was fixed that allowed us to build the webgl at least now but now when run the WebGL build and try to connect I get errors with UNetTransport and after some research someone recommended the WebSocketTransport from the community github.

    I got that installed and built and now when I connect I get the connect event on the server side but then I get disconnected with no details and this error is in the webgl logs:

    The JavaScript function 'Pointer_stringify(ptrToSomeCString)' is obsoleted and will be removed in a future Unity version. Please call 'UTF8ToString(ptrToSomeCString)' instead.

    Invoking error handler due to ReferenceError: Runtime is not defined unityFramework/__Connect/state.ws.onclose@http://localhost:54639/Build/webgl.framework.js.gz:3:72053

    I actually have very basic networking requirements and am just using the CustomMessagingHandlers and its a shame that this doesn't work on WebGL.
     
    Last edited: Jul 19, 2022
  2. Brian-Kryptomon

    Brian-Kryptomon

    Joined:
    Apr 17, 2022
    Posts:
    15
    I noticed this server side too in the logs - seems like I'm actually not getting a connect event, only a disconnect event. Not sure it helps.

    Disconnected Client: 1
    7/19/2022 4:30:43 PM|Fatal|<>c__DisplayClass174_0.<startReceiving>b__2|System.ObjectDisposedException: Cannot access a disposed object.
    Object name: 'System.Net.Sockets.NetworkStream'.
    at System.Net.Sockets.NetworkStream.EndRead (System.IAsyncResult asyncResult) [0x00015] in <bbae6af52a2a4bd982f8fde9721d2c3b>:0
    at WebSocketSharp.Ext+<>c__DisplayClass57_0.<ReadBytesAsync>b__0 (System.IAsyncResult ar) [0x00000] in <45d4bd6c2c784e299b2222abed0163a1>:0
     
  3. Brian-Kryptomon

    Brian-Kryptomon

    Joined:
    Apr 17, 2022
    Posts:
    15
    @JoshPeterson

    Thanks for your help on getting that build issue with the webgl netcode library resolved. I am running 2021.3.6f1 and the webgl builds seem to have issues with websockets now. Do you know if this is a known issue?
     
  4. Brian-Kryptomon

    Brian-Kryptomon

    Joined:
    Apr 17, 2022
    Posts:
    15
    Just an update - tracked down the issue to a bad library in the web socket transport project.

    I fixed it and now it connects and passes data to the server but I’m getting a warning on every message coming down to the client:


    [Netcode] Received a packet too small to contain a BatchHeader. Ignoring it.

    The clients getting the messages as this warning comes up every time the server would be sending a message.

    Any thoughts now that I’ve gotten it down to netcode? Or any idea on how to see the packets or troubleshoot.
     
  5. Saltant

    Saltant

    Joined:
    Aug 15, 2018
    Posts:
    1
    Did you correct the issue? When I try to transfer data through ServerRPC, I get the error
    "[Netcode] Received a packet too small to contain a BatchHeader. Ignoring it."
    and the data is not transferred between client and server, serverRPC does not work.
     
  6. thamrick

    thamrick

    Joined:
    Sep 19, 2022
    Posts:
    6
    Any luck with this? I'm stuck in the same place. [Netcode] Received a packet too small..." and only a disconnect on server.
     
  7. unity_3TAZt76MuKiOEg

    unity_3TAZt76MuKiOEg

    Joined:
    Sep 10, 2021
    Posts:
    1
    I had this issue with Unity for Webgl + Netcode, I "kind of" resolved it by changing this kinds of lines :
    Module['dynCall_vii']( ..., [*]) by Module['dynCall_vii']( ..., *). ( I removed the [ ], put kept what was inside ). You have to do that for every Module['dynCall_something'] ( I had 4 in my case ), inside your build.framework.js.
    upload_2022-10-3_9-34-1.png
    upload_2022-10-3_9-34-19.png
    before/after

    upload_2022-10-3_9-34-58.png
    4 to edit


    Also I have a second error where Unity Webgl with Netcode build using Runtime.dynCall(...) instead of Module["dynCall..."] ( I had to replace these manually to make it work )

    Hope this help ...