Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Unity Multiplayer Mirror - Networking for Unity (UNET Replacement)

Discussion in 'Connected Games' started by vis2k, Aug 11, 2016.

  1. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    68
    Upon doing some digging I found another issue. It seems that the Editor Preview for the NetworkTransform (?) is glitching out with a NullReferenceException, even if you're not in play mode?

    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. UnityEditor.Networking.NetworkTransformPreview.OnPreviewGUI (Rect r, UnityEngine.GUIStyle background)
    4. UnityEditor.ObjectPreview.OnInteractivePreviewGUI (Rect r, UnityEngine.GUIStyle background) (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:113)
    5. UnityEditor.ObjectPreview.DrawPreview (IPreviewable defaultPreview, Rect previewArea, UnityEngine.Object[] targets) (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:223)
    6. UnityEditor.ObjectPreview.DrawPreview (Rect previewArea) (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:127)
    7. UnityEditor.InspectorWindow.DrawPreviewAndLabels () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:767)
    8. UnityEditor.InspectorWindow.OnGUI () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:397)
    9. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
    10. Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    11. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
    12. System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
    13. UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:295)
    14. UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:288)
    15. UnityEditor.HostView.InvokeOnGUI (Rect onGUIPosition) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:255)
    16.  
    Here's what I see when I set up a cube GameObject with NetworkTransform:


    Here's what I see when I set up a character with Opsive's TPC Network Setup script which adds a NetworkTransform automatically:


    As you can see, they aren't consistent for whatever reason.

    Do you know what could be triggering this?

    EDIT: Well it seems that I fixed whatever was causing the unknown message ID call. Must have been something in an override of mine because I double and triple checked the code and it was supposed to be working as nature intended... but whatever. It's not a fault of HLAPI Community Edition. Strike that one off the list... for now.
     
    Last edited: Jul 1, 2018
    vis2k likes this.
  2. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    About NetworkTransformEditor: please try original hlapi and see if it happens there too or not.
     
  3. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    68
    @vis2k Just tested original DLLs, same issue is present.
    For it to be triggered, you need a following:

    1. Create a GameObject with whatever. Fo this example, I used a
    2. Add a Network Identity, Network Transform and Network Animator (note that some of these components may not be required, but that's what I can confirm triggers it for me).
    3. In the bottom part, observe that it should look like this:

    4. Add a Rigidbody 2D or Rigidbody 3D. Click anywhere to deselect the gameobject.
    5. Click the gameobject again and check "Network Transform" in the inspector (bottom part).
    5. "Network Transform" info should not be showing a "Last SyncTime: (value)". The console will be emitting the following error every refresh of OnGUI (depends how fast you move mouse or change settings for the amount of stuff being emitted)
    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. UnityEditor.Networking.NetworkTransformPreview.OnPreviewGUI (Rect r, UnityEngine.GUIStyle background) (at C:/buildslave/unity/build/Extensions/Networking/Editor/NetworkTransformPreview.cs:55)
    4. UnityEditor.ObjectPreview.OnInteractivePreviewGUI (Rect r, UnityEngine.GUIStyle background) (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:113)
    5. UnityEditor.ObjectPreview.DrawPreview (IPreviewable defaultPreview, Rect previewArea, UnityEngine.Object[] targets) (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:223)
    6. UnityEditor.ObjectPreview.DrawPreview (Rect previewArea) (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:127)
    7. UnityEditor.InspectorWindow.DrawPreviewAndLabels () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:767)
    8. UnityEditor.InspectorWindow.OnGUI () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:397)
    9. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
    10. Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    11. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
    12. System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
    13. UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:295)
    14. UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:288)
    15. UnityEditor.HostView.InvokeOnGUI (Rect onGUIPosition) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:255)
    16.  
    6. There is no step 6, you've replicated the problem!

    To fix this, remove the R2D or R3D and you will no longer get the errors being emitted.
     
  4. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Will put it on my list
     
  5. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    68
    Thanks vis2k. I really need to start throwing coins in your jar.

    EDIT: Got a different error this time when loading up my project and looking at a character's NetworkTransform:

    Code (csharp):
    1.  
    2. UnassignedReferenceException: The variable m_RigidBody3D of NetworkTransform has not been assigned.
    3. You probably need to assign the m_RigidBody3D variable of the NetworkTransform script in the inspector.
    4. UnityEngine.Rigidbody.get_rotation () (at C:/buildslave/unity/build/artifacts/generated/common/modules/Physics/DynamicsBindings.gen.cs:1660)
    5. UnityEditor.Networking.NetworkTransformPreview.OnPreviewGUI (Rect r, UnityEngine.GUIStyle background)
    6. UnityEditor.ObjectPreview.OnInteractivePreviewGUI (Rect r, UnityEngine.GUIStyle background) (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:113)
    7. UnityEditor.ObjectPreview.DrawPreview (IPreviewable defaultPreview, Rect previewArea, UnityEngine.Object[] targets) (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:223)
    8. UnityEditor.ObjectPreview.DrawPreview (Rect previewArea) (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:127)
    9. UnityEditor.InspectorWindow.DrawPreviewAndLabels () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:767)
    10. UnityEditor.InspectorWindow.OnGUI () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:397)
    11. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
    12. Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    13. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
    14. System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
    15. UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:295)
    16. UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:288)
    17. UnityEditor.HostView.InvokeOnGUI (Rect onGUIPosition) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:255)
    18.  
    Yet the Rigidbody is definitely attached to the gameobject.
     
    Last edited: Jul 3, 2018
  6. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    41
    Hey peeps,

    I'm going to upgrade to pro! Is page 1 of this thread the best place to get the latest package?? I'm on 2018.1.6f1

    Thanks!
     
  7. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Yes
     
  8. natepacyga

    natepacyga

    Joined:
    Apr 7, 2015
    Posts:
    17
    I am using the HLAPI Community edition and I get a couple errors after about a minute or so on a connected client:
    SendToTransport failed. error:WrongConnection channel:1 bytesToSend:477
    UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

    then:
    ClientDisconnected due to error: Timeout

    On both the client and server, I am sending data so I don't know why it would timeout...? I am using a good amount of syncvars on my player gameobject, but in different scripts (I am probably close to 64 between the scripts that have them, but not all of them are dirty all the time). Just curious if anyone has run into these errors before.
     
  9. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    68
    Are you on a unstable network connection? Is this a local area network (ie. Your PC <-> Router <-> Other PC)? Or is this a client instance on the same PC? What version of Unity?

    Only time that I get that error is if I have killed the host instance with clients connected. The clients usually hang for a moment and then all network objects get deactivated.

    Maybe on the server keep an eye on the LMT (last message time) property of the connections. That might help find the culprit, but it might just be a packet got lost in transit and it shat itself.
     
    Last edited: Jul 4, 2018
  10. natepacyga

    natepacyga

    Joined:
    Apr 7, 2015
    Posts:
    17
    I am on Unity 2017.4.5f1. This is only on remotely connected computers in my office (Unity Matchmaking and using their service) and the connection should be great. (No indication that anything should be wrong) The silly thing is that everything connects just fine, but then after a minute or so it poops out with the aforementioned errors... I just want to make sure that UNet is a solid technology to build multiplayer games on top of...

    Good tip on the last message time @MCoburn, I'll check that out too.
     
  11. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    68
    Hmm, here's another interesting thing for investigating:

    If you use NetworkManagerHUD to spawn a LAN Host, shut it down with connected clients and then start the LAN Host again, you can get the NetworkManager to emit a NullReferenceException. It is worth noting though the Network Server will spawn correctly and accept connections, just local player will not spawn correctly for the second host instance.

    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. UnityEngine.Networking.NetworkConnection.InvokeHandler (Int16 msgType, UnityEngine.Networking.NetworkReader reader, Int32 channelId)
    4. UnityEngine.Networking.NetworkConnection.InvokeHandlerNoData (Int16 msgType)
    5. UnityEngine.Networking.NetworkServer.AddLocalClient (UnityEngine.Networking.LocalClient localClient)
    6. UnityEngine.Networking.LocalClient.InternalConnectLocalServer (Boolean generateConnectMsg)
    7. UnityEngine.Networking.ClientScene.ConnectLocalServer ()
    8. UnityEngine.Networking.NetworkManager.ConnectLocalClient ()
    9. UnityEngine.Networking.NetworkManager.StartHost ()
    10. UnityEngine.Networking.NetworkManagerHUD.OnGUI ()
    11.  
    I'll try to replicate this using a basic test project in the coming day or two, it might be related to the kits I'm using (doubt it because I can't see their calls in the stack trace).

    I suppose I need to check the original DLLs as well..
     
  12. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    What services do you mean exactly? Relay?

    And does it happen with original HLAPI?
    Does it happen with 2017.4 HLAPI CE?
    Does it happen with 2017.4_improvements HLAPI CE?
    Could you perhaps go through a few commits, build them, then try the DLLs to figure out when it started happening?
     
  13. natepacyga

    natepacyga

    Joined:
    Apr 7, 2015
    Posts:
    17
    @vis2k I actually purchased your uSurvival asset to learn more about UNet (I have previous knowledge in other networking technologies) and I have been happy with it. I have setup your asset to work in a remote connection setting as well. I haven't been able to get this error to happen in your uSurvival asset, which makes me think I am just sending too much data over X amount of time (which in this case happens in a minute or so).

    And does it happen with original HLAPI? - I haven't tried this, I will do that tomorrow (its the 4th of July and hanging with family today)
    Does it happen with 2017.4 HLAPI CE? - Yes, I am using this version.
    Does it happen with 2017.4_improvements HLAPI CE? - Haven't yet
    Could you perhaps go through a few commits, build them, then try the DLLs to figure out when it started happening? - Sure, if I have to go back through versions, I can. But really I think I need to compare what you did in uSurvival and how I could be so different.

    Attached is my NetworkManager implementation which is a stripped version of the uSurvival NetworkManager. I hope you don't mind me posting it @vis2k but it is very stripped down, but I am happy to take it down if you do mind.

    I did a count and I have 34 SyncVars along with 34 matching Commands to change those states from the client side. In another class on the same game object I have 20 SyncVars along with 20 Commands to change their state on the client.

    So they look like:
    [SyncVar, HideInInspector] public bool isChangingWeaponSyncVar;
    [Command(channel = Channels.DefaultUnreliable)] public void CmdIsChangingWeaponSyncVar(bool value) { isChangingWeaponSyncVar = value; }

    Thanks guys for all the help / advice on this. I really want to make this all work on UNet.

    @MCoburn I am not using NetworkManagerHUD as talked about in the beginning I am using @vis2k 's asset as a base and building off of that.
     

    Attached Files:

  14. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    If it works fine with the default uSurvival networkmanager and then it stops working when you modified it, then it's probably something in your modifications. I don't really have the time to debug other people's projects to be honest, I think you'll have to figure this out yourself. All the source is there, grab the debugger and try :)

    If you find a bug that is easy to reproduce then let me know and I'll fix it of course!
     
  15. natepacyga

    natepacyga

    Joined:
    Apr 7, 2015
    Posts:
    17
    I know I posted the file, but I wouldn't expect you to debug it. It was more of a look over and to see if you guys have run into any of the issues I am having. I don't think it's my NetworkManager, I think it's the amount of SyncVars and the data being sent, which is a bit concerning to me as I am just moving players around. I will come back and report what I find, I just hope that UNet is a actual networking solution I can use...
     
    Last edited: Jul 5, 2018
    vis2k likes this.
  16. natepacyga

    natepacyga

    Joined:
    Apr 7, 2015
    Posts:
    17
    @vis2k @MCoburn It was the number of Commands I had in my classes. It was just simply too many updates to the server. It seems having one Command with a large amount of arguments is better over many Commands. Which does make sense depending on how they are handled under the hood. Funny thing, as I pointed out, that it took a minute or so for Unity / UNet to choke on it. Just wanted to report back on this. Thanks guys for posting replies on it.
     
    MCoburn and vis2k like this.
  17. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    68
    Consider using a JSON blob and sending that back and forth. It may be more data over the network but you can serialise a lot of data into JSON text string and have it unpacked on the server, etc.

    I use JSON for scoreboard updates where the server sends all clients the updated scoreboard every time there's an update.
     
  18. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    68
    I had an issue where I thought the community version (improvements branch) of UNET was causing packet loss over a Wireless client PC connecting to a LAN computer running Unity Editor as the Host as everything would freeze over the network intermittently and then it would "pop" to the correct locations on the client when it unfroze. The editor displayed everything fine during the client "freeze", but the client would have a delay.

    This doesn't happen on wired LAN computers it seems. I then ran iperf3 for Windows and checked the bandwidth between the wifi client and the host - sure enough, the wifi connection throughput on the client was very patchy (even if the router was just across the desk from it!). I can't seem to get this issue to fire unless the host instance does something very intensive that is spamming the CPU, and iperf3 on a LAN pretty much saturates the cable.

    Just keep that in mind when using UNET and testing your game network code in your local network. For a ideal setup, I'd recommend using a switch and wired connections, but I guess you need to test it over wifi as well to cover all bases so that'll suffice.

    BTW... Has anyone used the network simulator option in the NetworkManager?
     
  19. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Good morning everyone.

    Working on the 'community' part of HLAPI Community Edition now.
    Feel free to join our new Discord: https://discord.gg/N9QVxbM
    We can discuss features, goals, etc. there!

    Edit: also added explanations about branches, so people don't get disappointed about rejected pull requests.
     
    Last edited: Jul 15, 2018
  20. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    473
    Trying to pass png as bytes from client to server, however I am getting this error:

    Code (CSharp):
    1. IndexOutOfRangeException: NetworkReader:ReadByte out of range:NetBuf sz:0 pos:0
    2. UnityEngine.Networking.NetBuffer.ReadByte ()
    3. UnityEngine.Networking.NetworkReader.ReadUInt16 ()
    4. UnityEngine.Networking.NetworkReader.ReadBytesAndSize ()
    5. SendData.Deserialize (UnityEngine.Networking.NetworkReader reader) (at Assets/ClientMenuServer.cs:15)
    6. UnityEngine.Networking.NetworkMessage.ReadMessage[SendData] ()
    7. ServerScript.ReceiveSelfie (UnityEngine.Networking.NetworkMessage myMessage) (at Assets/ServerScript.cs:46)
    8. UnityEngine.Networking.NetworkConnection.HandleReader (UnityEngine.Networking.NetworkReader reader, Int32 receivedSize, Int32 channelId)
    9. UnityEngine.Networking.NetworkConnection.HandleBytes (System.Byte[] buffer, Int32 receivedSize, Int32 channelId)
    10. UnityEngine.Networking.NetworkConnection.TransportReceive (System.Byte[] bytes, Int32 numBytes, Int32 channelId)
    11. UnityEngine.Networking.NetworkServer.OnData (UnityEngine.Networking.NetworkConnection conn, Int32 receivedSize, Int32 channelId)
    12. UnityEngine.Networking.NetworkServer+ServerSimpleWrapper.OnData (UnityEngine.Networking.NetworkConnection conn, Int32 receivedSize, Int32 channelId)
    13. UnityEngine.Networking.NetworkServerSimple.HandleData (Int32 connectionId, Int32 channelId, Int32 receivedSize, Byte error)
    14. UnityEngine.Networking.NetworkServerSimple.Update ()
    15. UnityEngine.Networking.NetworkServer.InternalUpdate ()
    16. UnityEngine.Networking.NetworkServer.Update ()
    17. UnityEngine.Networking.NetworkIdentity.UNetStaticUpdate ()
     
  21. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    1. Use improvements version. Fixes this error appearing randomly and shows better debug message.
    2. Please don't ask here and in discord. Only ask at one place and we don't have to reply twice.
     
  22. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    41
    Hi,

    Can anyone recommend a good dedicated server package that is tested and working well with UNET community ed?

    Thanks!
     
  23. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Namecheap works
     
    Roamer79 likes this.
  24. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Update: uploaded latest 2017.4_improvements DLLs. A lot of small improvements, and two major big ones:

    • NetworkCRC removed
      • NetworkCRC sent all NetworkBehaviour script names over the network, only to compare their channelIds with those on the server. This used a lot of bandwidth for virtually no benefit. Why would anyone build the server, then modify a script's channel for no reason, then build the client? A real CRC for the whole project might have been useful, but only comparing channelIds is not worth the bandwidth and code complexity at all.
    • ChannelBuffer/ChannelPacket removed
      • NetworkConnection had a list of ChannelBuffers, each of them had a ChannelPacket. This was implemented to provide reliable messages, message fragmentation and send delay buffering before NetworkTransport implemented those features. NetworkTransport does implement those features now, so it's enough if we send all messages directly to NetworkTransport.
        • => Significantly reduces memory consumption and GC for each packet
        • => Reduces computations needed to buffer and fragment packets
        • => Reduces latency because HLAPI and LLAPI don't both have a SendDelay anymore, only LLAPI

      The HLAPI code is getting better and less complex every day, and performance, gc, bandwidth and stability are also improving constantly!
     
    Hawkadium, Dareheim, moco2k and 2 others like this.
  25. Dimitri0xff

    Dimitri0xff

    Joined:
    Jul 1, 2018
    Posts:
    1
    Hello,

    Is the "SyncVars getting desynced on player join" bug fixed either in the official Unity 2018.1 or in the HLAPI Community Edition fixes branch?
    I've been searching for this, also checked the repository, but haven't found anything. Thank you.

    Also, you could consider using the Bitbucket built-in Issue Tracker.
     
  26. RikuTheFuffs

    RikuTheFuffs

    Joined:
    Sep 9, 2013
    Posts:
    10
    Hello everybody, I'm thinking about switching to this version of the HLAPI, but I wonder if it allows for "reconnection" (I.E: someone closes the game by accident while playing and wants to come back to the same match). In the standard HLAPI this is not possible because "hot-join" is prevented.
     
  27. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Try fixes, then try the improvements version and let us know if it fixes it or not.
    I never heard of this bug. If it still exists then please send us a project where we can reproduce it to fix it.
     
  28. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    already answered you in discord. please don't ask questions in two places
     
  29. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Update: uploaded latest 2017.4 fixes and 2017.4 improvements DLLs. Found (and fixed) an interesting bug today where HLAPI sent a message with the wrong MsgType opcode to the client, result in NetworkReader trying to read invalid data and causing errors.

    With the built in HLAPI it's impossible to overwrite NetworkManager.OnServerAddPlayer to spawn a player object that's already in the scene while running in host mode. Looks like the code was implemented without ever being tested.

    This is what caused the bug, notice how the lower half sends the wrong MsgType.
    bug screenshot.png


    Friendly reminder that we are fixing Unity's bugs for free. Please support us on Patreon if you benefit from our work.
     
    Last edited: Jul 20, 2018
  30. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    AwesomeX likes this.
  31. IEdge

    IEdge

    Joined:
    Mar 25, 2017
    Posts:
    28
    I was just looking for a solution to my problem and I came across this thread by chance... If you tell me that it is possible to solve it with your UNET Community Edition, I will simply give you a +rep!
     
  32. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Feel free to try the improvements DLLs and let us know if it worked or not..
     
  33. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Huge Update: latest improvements version cuts bandwidth at least in half, more likely a 2-10 fold reduction in most projects. UNET's serialization code was really poorly designed, serializing all the components for all the channels all the time. What the hell Unity?

    Latest improvements DLLs can be found in first post.

    Changelog:
    • NetworkIdentity.UNetUpdate serialization Bandwidth overkill fixed
    • Problem: NetworkIdentity.UNetUpdate serialized all components for each channel if any component for the channel was dirty. This caused at least twice the unnecessary bandwidth, usually even more:
      • Most UNET projects use at least two channels: Unreliable and Reliable. So all of the components would be serialized once for Unreliable and then once again for Reliable and then sent over the Network, doubling the necessary bandwidth just about all the time. If a project uses 5 channels, then it would be 5x the unnecessary bandwidth. This is completely insane.
      • If one component was dirty then all components would be synced and sent over the network again. For example, if the player moves and the component gets dirty, then not just the movement, but also all other components like Health, NetworkTime, etc. would be serialized. If the player has 10 components and only one of them is dirty, then all 10 would be serialized. This again causes unnecessary bandwidth depending on the amount of your components, so it can easily cause 10x the required bandwidth. This too is completely insane.
      • Additionally, the SendInterval setting was almost entirely ignored because OnSerialize would be called if another component's sendInterval was elapsed.
    • Solution: a dirtyComponents bit mask is included in each serialization. Only the dirty components for a given channel are serialized.
    I will start another community stress test for my uSurvival asset soon to get some detailed numbers on the improvements here.

    ... in other words: UNET on steroids.
     
    Last edited: Jul 22, 2018
    Hitch42, moco2k and goldbug like this.
  34. marcV2g

    marcV2g

    Joined:
    Jan 11, 2016
    Posts:
    115
    So I have not check here in a few months,

    did the possibility of these fixes being added to unity3d main branch go anywhere?
     
  35. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    693
    If you look at their repository, they have never merged any pull request. They just don't take code from other people at all.
     
  36. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Unity tried to use my postprocess sceneid fix, but they didn't use the exact same code and failed to do it properly, the bug is still there.
     
  37. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Been researching some bandwidth optimizations, turns out that UNET already does a pretty good job on that. Added some notes to the first post, for those who care:

    UNET Byte Optimizations

    The UNET Weaver automatically uses WritePackedUInt for:
    • SyncVars
    • SyncListStruct's structs
    • Messages that inherit from MessageBase
    • Command/Rpc parameters
    So for example, if you have a 'health' SyncVar that uses int, you won't gain anything by converting it to 'short' since UNET uses the WritePacked version anyway. This is really useful since dealing with bytes and shorts in C# isn't very pleasant.

    The only thing left for the user to optimize are custom OnSerialize/OnDeserialize functions.
     
    Last edited: Jul 24, 2018
  38. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    41
    Just like to say that you have been doing amazing work. Unet was unusable for my application and since upgrading to community I am very close to getting a workable networked game! Still, it is a little difficult being a novice but getting there!

    Regarding the above Byte Optimizations. I'm still not 100% happy with the built in network transform module. Its def better but I get such amazing syncing results using a custom script based on Vector3 and Quaternion SyncVars. Problem is I get the feeling this method is heavy lifting and I am pumping too much data down the network. Does byte optimization do anything when sending Vector3's and such??
     
    vis2k likes this.
  39. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    I am 0% happy with the built in NetworkTransform. It's not highest priority, but we will fix this at some point!
     
  40. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    41
    Hahha good! At least I'm not crazy!!
     
  41. PartyBoat

    PartyBoat

    Joined:
    Oct 21, 2012
    Posts:
    82
    Is any support for 2018.2 planned or is this project mostly sticking to the 2017.4 LTS cycle?
     
  42. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Try the 2018.1 download in the first post. Need to update it to the latest fixes again, but it should work.

    UNET team didn't upload 2018.2 HLAPI source yet: https://bitbucket.org/Unity-Technologies/networking/branches/ . Feel free to ask them.
     
  43. dkstrong

    dkstrong

    Joined:
    Aug 17, 2013
    Posts:
    16
    I wouldnt make NetworkServer in to static. The singleton pattern allows for using a mock NetworkServer with testing.
     
  44. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Take a look at the old NetworkServer + NetworkServerSimple code, it doesn't make testing very enjoyable :)
     
  45. PartyBoat

    PartyBoat

    Joined:
    Oct 21, 2012
    Posts:
    82
    Ah, that makes sense. I'll give your suggestion a shot.
     
  46. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    693
    This puts things in perspective.

    fixes branch:

    Code (csharp):
    1. -------------------------------------------------------------------------------
    2. Language                     files          blank        comment           code
    3. -------------------------------------------------------------------------------
    4. C#                              41           2599            731          14579
    5. MSBuild script                   1              0              5             91
    6. -------------------------------------------------------------------------------
    7. SUM:                            42           2599            736          14670
    8. -------------------------------------------------------------------------------
    improvements branch:

    Code (csharp):
    1. -------------------------------------------------------------------------------
    2. Language                     files          blank        comment           code
    3. -------------------------------------------------------------------------------
    4. C#                              31           1742            640           9693
    5. MSBuild script                   1              0              5             81
    6. -------------------------------------------------------------------------------
    7. SUM:                            32           1742            645           9774
    That only includes the Runtime part of HLAPI CE.

    This means we have removed 34% of the code. I am sure a lot of bugs were lurking under the surface in there.
     
    runningbird, Jos-Yule, vis2k and 2 others like this.
  47. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    693
    Another nice improvement. Let's say you have this code:
    Code (CSharp):
    1. public class SampleBehavior : NetworkBehaviour
    2. {
    3.  
    4.     [SyncVar]
    5.     public int intData;
    6.     [SyncVar]
    7.     public string strData;
    8.  
    9.     public SyncListInt intsynclist = new SyncListInt();
    10. }
    HLAPI sees that code and generates a OnSerialize method for your class. This is what HLAPI regurgitates:
    Code (CSharp):
    1. public override bool OnSerialize(NetworkWriter writer, bool forceAll)
    2. {
    3.     if (forceAll)
    4.     {
    5.         writer.WritePackedUInt32((uint)this.intData);
    6.         writer.Write(this.strData);
    7.         SyncListInt.WriteInstance(writer, this.intsynclist);
    8.         return true;
    9.     }
    10.     bool flag = false;
    11.     if ((base.get_syncVarDirtyBits() & 1uL) != 0uL)
    12.     {
    13.         if (!flag)
    14.         {
    15.             writer.WritePackedUInt64(base.get_syncVarDirtyBits());
    16.             flag = true;
    17.         }
    18.         writer.WritePackedUInt32((uint)this.intData);
    19.     }
    20.     if ((base.get_syncVarDirtyBits() & 2uL) != 0uL)
    21.     {
    22.         if (!flag)
    23.         {
    24.             writer.WritePackedUInt64(base.get_syncVarDirtyBits());
    25.             flag = true;
    26.         }
    27.         writer.Write(this.strData);
    28.     }
    29.     if ((base.get_syncVarDirtyBits() & 4uL) != 0uL)
    30.     {
    31.         if (!flag)
    32.         {
    33.             writer.WritePackedUInt64(base.get_syncVarDirtyBits());
    34.             flag = true;
    35.         }
    36.         SyncListInt.WriteInstance(writer, this.intsynclist);
    37.     }
    38.     if (!flag)
    39.     {
    40.         writer.WritePackedUInt64(base.get_syncVarDirtyBits());
    41.     }
    42.     return flag;
    43. }
    And this is what HLAPI CE improvements produces now:
    Code (CSharp):
    1. public override bool OnSerialize(NetworkWriter writer, bool forceAll)
    2. {
    3.     bool result = false;
    4.     if (forceAll)
    5.     {
    6.         writer.WritePackedUInt32((uint)this.intData);
    7.         writer.Write(this.strData);
    8.         SyncListInt.WriteInstance(writer, this.intsynclist);
    9.         return true;
    10.     }
    11.     writer.WritePackedUInt64(base.get_syncVarDirtyBits());
    12.     if ((base.get_syncVarDirtyBits() & 1uL) != 0uL)
    13.     {
    14.         writer.WritePackedUInt32((uint)this.intData);
    15.         result = true;
    16.     }
    17.     if ((base.get_syncVarDirtyBits() & 2uL) != 0uL)
    18.     {
    19.         writer.Write(this.strData);
    20.         result = true;
    21.     }
    22.     if ((base.get_syncVarDirtyBits() & 4uL) != 0uL)
    23.     {
    24.         SyncListInt.WriteInstance(writer, this.intsynclist);
    25.         result = true;
    26.     }
    27.     return result;
    28. }
    Unity's logic in a nutshell:
     
    Last edited: Jul 27, 2018
    HeadClot88, marcV2g and vis2k like this.
  48. dkstrong

    dkstrong

    Joined:
    Aug 17, 2013
    Posts:
    16
    NetworkServerSimple to me looks like an attempt to fix the design mistakes of NetworkServer. but was never finished.
     
  49. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Hence why we removed it. It's also insanely complex.
     
  50. Dareheim

    Dareheim

    Joined:
    Oct 12, 2013
    Posts:
    7
    I apologize for my English, translate it using google translate
    After the last two updates, my project began to swear at the following:

    Code (CSharp):
    1.         NetworkServer.RegisterHandler(MsgType.AddPlayer, OnAddPlayerMessage);
    2.         NetworkServer.RegisterHandler(MsgType.Disconnect, OnDisconnect);
    3.         NetworkServer.RegisterHandler(MsgType.Connect, OnConnected);
    error CS1502: The best overloaded method match for `UnityEngine.Networking.NetworkServer.RegisterHandler(short, UnityEngine.Networking.NetworkMessageDelegate)' has some invalid arguments
    error CS1503: Argument `#1' cannot convert `UnityEngine.Networking.MsgType' expression to type `short'

    Code (CSharp):
    1.              public static short UID = MsgType.Highest + 1;
    2.             public static short Custom = MsgType.Highest + 2;
    3.             public static short Crypt = MsgType.Highest + 3;
    error CS0266: Cannot implicitly convert type `UnityEngine.Networking.MsgType' to `short'. An explicit conversion exists (are you missing a cast?)

    and

    Code (CSharp):
    1.         ClientScene.readyConnection.SendWriter(m_LocalTransformWriter, GetNetworkChannel());
    error CS1061: Type `UnityEngine.Networking.NetworkConnection' does not contain a definition for `SendWriter' and no extension method `SendWriter' of type `UnityEngine.Networking.NetworkConnection' could be found

    How can I fix this?