Search Unity

Showcase Mirror - Open Source Networking for Unity

Discussion in 'Multiplayer' started by mischa2k, Aug 11, 2016.

  1. GoDJaMMing

    GoDJaMMing

    Joined:
    Feb 4, 2014
    Posts:
    7
    ur a beast, keep that good work up
     
    bvicil and mischa2k like this.
  2. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Update: more new stuff for the improvements branch. New DLLs were uploaded.
    NetworkReader/Writer use C#'s built in BinaryReader/Writer, this makes the code a LOT shorter and more stable.
    Also removed some obsolte functions, some static message caching and some redundant .ToArray/AsArray/AsArraySegment functions and constructors.

    This was a really important change for stability, since the C# built in BinaryReader/Writer classes can be considered bug free.

    Thanks
     
  3. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    News: renamed this thread and the repository to HLAPI Community Edition. UNET team wanted to do that anyway, but they didn't follow up on their promise. We have the HLAPI source, we are the community and no one else wanted to do it anyway. Please take a look at the first page again, I will keep the fixes-only branches that everyone can use and I'll continue to go crazy on the improvements branch.

    License:
    New license file should be up soon, and you'll like it a lot.

    Regular branches received a few more important bug fixes, there was an issue with the max packet size where HLAPI sometimes used short.max and ushort.max. It's consistently ushort.max now.

    Improvements branch will get more major improvements. I'll probably remove the host migration feature since it's not stable, makes the code way too complicated and hosting multiplayer games on people's computers sucks anyway.

    Also thanks to @goldbug for the suggestions, discussions and looking over my code.
     
    Last edited: Jun 13, 2018
    nirvanajie, bartuq, akuno and 4 others like this.
  4. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    News: new license and more updates to the Improvements branch (removed host migration because it wasn't stable and hosting on other people's computers always sucks). Original lines of code = 21129; Improvements = 19113. Roughly 10% shorter now. 10% less code that can cause bugs.

    New License (from first post):
    Please respect the LICENSE.txt in the repository.
    (You can embed the DLL files into your game).

    Note: I am doing Unity's work without being on their payroll. So while you can use the DLLs for free, I'd like to reserve my rights to the source code for now.
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    What was this impacting? Is this a global setting that overrides ChannelOption.MaxPendingBuffers? Or am I misunderstanding?
     
  6. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Impacts ChannelBuffer.m_MaxPendingPacketCount . Well now it does, previously it did nothing.
     
  7. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Update (improvements branch): NetworkServerSimple removed and NetworkServer made entirely static, like it should be.
    • Unity added NetworkServerSimple a while after someone requested server parts to be replaceable at runtime. A good idea in theory, but the amount of complexity this caused is completely insane and no one seemed to be using it anyway.
    • NetworkServer is meant as a static class, but Unity used the singleton pattern. The code always expects exactly one server, so making it static makes perfect sense and simplifies the code a lot.
    • Improves performance a bit since all those .instance getter logic/checks are gone.
    • Less state == good.
    Also thanks to @goldbug the project now builds at first try, because it's not dependent on Output DLLs anymore.

    Original LOC: 21129
    Improvements LOC: 18885
     
  8. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I must be the only one using NetworkServerSimple then. I've found it extremely useful for server to server communication, and client to server for non-gameplay related services, such as my login server. Is there an alternative that still implements Messages?
     
  9. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    You can use the 2017.4 branch that only has fixes.
    Can you make a case for NetworkServerSimple? Why do you need to inherit from it and replace it and why is it not better to modify the NetworkManager or HLAPI source for that?

    It really does make the source very messy.
     
  10. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Yes thank you. I haven't started using community edition yet, but your recent max buffered packets fix is something I'm needing to include so I'll be switching over at some point soon.

    I'm not sure I can, because I haven't looked through the HLAPI code to understand how it all works underneath.

    I use NetworkServerSimple when I only want the Messages portion of the HLAPI, and will not be using networked objects, NetworkBehaviours, Player prefabs, etc. For example, my zone servers run a full NetworkManager with all the HLAPI features for clients to connect to play the game. The zone servers connect to other servers to access and share data and to take commands from the master server. All those other servers are just running NetworkServerSimple, but are the same build as the zone servers, but just running a different scene.

    Modifying a NetworkManager or HLAPI source wasn't better from my perspective because NetworkServerSimple was exactly the functionality I needed for server to server coms, so I'd be making those modifications to emulate something already available. Though I could give that a try if I wanted any of your other improvements (there's several I do want). I'm pretty sure I can't go the NetworkManager route anyway, as I don't think I can run multiple NetworkManagers in the same scene.

    I'm not surprised. Rushed additions followed by years of no fixes or support rarely results in clean code.
     
    Last edited: Jun 23, 2018
  11. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    I see. Well none of this is set in stone. I am currently trying to clean up the improvements branch to point where it's maybe 15k or 10k LOC so people can modify it more easily (and debug etc.). Will have to think about that NetworkServerSimple thing again in the future. Maybe the better way is to use hooks or to make NetworkServer a class with virtual functions, so people can overwrite NetworkServer instead of NetworkServerSimple if necessary.

    Will see.
     
  12. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    @vis2k Could you please look into why OnStartClient() does not get fired more than once in the lifetime of a client starting up from the NetworkManagerHUD? This is very annoying if you register NetworkClient MessageHandlers and use the Network Manager HUD to spawn a new client, disconnect that client, and spawn a new one as clients will lose the MessageHandler you setup originally and thus be unable to handle custom message IDs.

    EDIT: tl;dr added to bottom of this post

    Unity version: 2017.4.3f1 (LTS) 64bit Free

    Here's how to trigger this very annoying bug/oversight:

    In a blank scene, create a empty gameobject at 0,0,0 and attach both Network Manager and Network Manager HUD objects. Now, make another cube and give it a NetworkBehaviour script and in your script, put this:

    Code (CSharp):
    1.  
    2. public int timesCalled = 0;
    3.  
    4. public override void OnStartClient() {
    5. #if UNITY_STANDALONE
    6.    // A quick trick to make the "error" appear in the Debug Console in the standalone instance.
    7.    Debug.LogError("Hello I'm called from OnStartClient on the client standalone instance!");
    8. #else
    9.    Debug.LogError("Hello I'm called from OnStartClient!");
    10. #endif
    11.    timesCalled += 1;
    12.  
    13.    base.OnStartClient();
    14. }
    The cube should be disabled on startup (ie. when the HUD appears that says LAN Host, LAN Client and LAN Server). If not, adjust where needed and try again. Now click LAN Host and you should see the Hello message in your editor because the NetworkBehaviour got the memo that the client is starting up.

    Now make a standalone build and connect to the host instance. You will get the message. Then stop the client, then start the client again. You will not get another Hello message. From what I can tell, on the standalone client the OnStartClient() does not run again if you stop and start the client instance, but it works on the Editor. I have no [redacted] idea why this happens but it's frustrating.

    BONUS: You can also reverse the roles of the standalone build and the editor and you'll get the same issue.

    I have reported this bug to Unity last night but am I yet to hear back a response. A bug fix on your behalf would be greatly appreciated. I can provide you the same project I sent to Unity Tech (it's basically a scene and some scripts) for further testing and debugging if you desire.

    tl;dr edition:
    EDITOR
    -- Start LAN Host
    --- Unity starts server instance
    --- Unity starts local client instance
    --- Scripts get the OnStartClient() call
    --- Everything is daijoubu.
    --- Stopping and restarting host works fine

    STANDALONE
    -- Start LAN Client
    --- Unity connects to editor host (good!)
    --- Scripts get the OnStartClient() call (good!)
    --- Everything is daijoubu.
    --- Stop the client and start it again
    --- Scripts DO NOT get the second OnStartClient() call (failure!)
    Seems to be due to that hook not being fired again on a new client instance?

    At this point any network message handlers you registered the first time are no longer registered and you'll get "Unknown message ID: 4000" for custom messages (4000 is just an example ID).
     
    Last edited: Jun 26, 2018
  13. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Will put it on my ToDo list. I believe we already have a pull request for that in the repository too, didn't test it yet.
    @goldbug is this the error that you had too?
     
  14. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    After some more testing, it seems the custom network message IDs get registered after the connection actually connects. I put a RegisterHandler(id, messagebase) call in a network behavior script inside OnStartClient() and then in the server code's NetworkManager class, did a NetworkServer.SendToAll(...) call. The standalone client would just error out with "Unknown Message ID 3500" instead of handling the packet - even though it seemed the NetworkClient RegisterHandler call didn't error. The editor, would handle it and behave correctly.

    I was using NetworkClient.allConnections[0].RegisterHandler() call because NetworkManager.client.RegisterHandler() seems to return a NullReferenceException (wait what?) at OnStartClient() time. I don't understand.

    Would you like me to upload you the test project that I supplied Unity Tech?
     
  15. Jos-Yule

    Jos-Yule

    Joined:
    Sep 17, 2012
    Posts:
    292
    FYI FWIW, my thinking about OnStartClient() was that it worked like monobehaviour's Start() method, it would only be called once. I can see that you could easily assume, alternatively, that it would be called each time the Client is started. Note that changing this behaviour could easily break existing code which depends on the original behaviour, even if it is "broken".
     
  16. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    767
    It may be related. I also don't get a second call to OnClientStart, however my scenario is slightly different:
    1. Create a project with a network game object in the scene.
    2. Start a host (does not matter if editor or standalone)
    3. Start a client instance (does not matter if editor or standalone)
    4. connect the client to the host
    5. disconnect (don't shut down the client)
    6. connect the client to the host again. The OnClientStart method is not called the second time.
     
    Last edited: Jun 27, 2018
  17. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    Well that would be weird because it says in the documentation that it is supposed to be called when the client starts which i would assume means every client instance it starts up.

    That is also what I'm experiencing. Let me do some further testing but I am still experiencing the Unknown Message ID firing before the handler is registered it seems.
     
    Last edited: Jun 27, 2018
  18. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    Okay, after a little bit more testing by using a different way of doing things using NetworkManager.singleton.client.RegisterHandler(id, handlerCallback) instead of NetworkClient.allClients[0].RegisterHandler(id, handlerCallback) and using a MonoBehaviour instead of a NetworkBehaviour, I can confirm that it's still very much broken.

    Editor client will get the packets fine. Standalone client will get the packets fine for one connection but as soon as you click "Stop" and "LAN Client" again, the handler goes bye-byes and hello Unknown Message ID.

    I suppose I'm gonna go back to good 'ol RPCs for now or give up on my netcode until we shine more light into this.

    EDIT: At what point in the HLAPI connection routines is the NetworkManager.singleton.client and/or NetworkClient.allClients[0].client (0 is your connection iirc) created? It seems that it's encountering a race condition where sometimes you get lucky, sometimes you don't. To me, it should be created from the get-go and ready to connect (and accept custom packet handlers) before it does anything else connection-wise. I'm really tempted to go into the source and analyze this myself.
     
    Last edited: Jun 27, 2018
  19. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    45

    What!! So it was ignoring the value in the inspector??? Is that why my buffers kept running over??
     
  20. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    It was ignoring the value yes.
    And probably yes.
    :)
     
  21. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    16 is max buffer for default HLAPI? Wow. Just, wow.
     
  22. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    767
    MCoburn likes this.
  23. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
  24. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    @goldbug

    You are seriously my hero. Can I buy you a beer?

    With your fix, the OnStartClient() FIRES EVERY TIME on both the Editor and Standalone instances. How could Unity Tech not have thought of resetting the states that your fix does? #blameUnityTech

    Here's the CustomPacketSpammer script that can be used to do further testing but this has (so far) immediately solved my headache.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5.  
    6. public class CustomPacketSpammer : NetworkBehaviour {
    7.  
    8.     public float m_SpamInterval = 3f;
    9.     private float m_NextSpam = 0f;
    10.  
    11.     public override void OnStartClient() {
    12.         base.OnStartClient();
    13.  
    14.         Debug.LogError("OnStartClient() was called CustomPacketSpammer!");
    15.         NetworkClient.allClients[0].RegisterHandler(1337, HandleSpamPacket);
    16.         Debug.LogError("Apparently registered packet handlers!");
    17.  
    18.         m_NextSpam = Time.time + m_SpamInterval;
    19.     }
    20.  
    21.     private void LateUpdate () {
    22.         if (m_NextSpam > 0f && Time.time >= m_NextSpam) SpamPacket();
    23.     }
    24.  
    25.     private void SpamPacket () {
    26.         m_NextSpam = Time.time + m_SpamInterval;
    27.         if (!isServer) return;
    28.  
    29.         NetworkServer.SendToAll(1337, new SpamPacketMsg());
    30.     }
    31.  
    32.     private void HandleSpamPacket(NetworkMessage netMsg)  {
    33. #if UNITY_EDITOR
    34.         Debug.LogWarning("Spam spam spam!");
    35. #else
    36.         Debug.LogError("Spam spam spam!");
    37. #endif
    38.     }
    39.  
    40.     private class SpamPacketMsg : MessageBase {
    41.         public string text = "This be spam!";
    42.     }
    43. }
     
    goldbug likes this.
  25. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Will go through more pull requests soon btw
     
  26. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    767
  27. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    Yeah, i was aware that Unity had abandoned pretty much everything to do with UNET HLAPI, they seem to be going the new-new before fix-fix route which I don't really approve of.

    But, that is when projects like this step in and throw out the old code with new, freshly fixed code.
     
  28. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    767
    MCoburn likes this.
  29. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    Confirmed working. Using the same script as above and how I detailed it in my commit on Bitbucket, did a best of 3, didn't fail once.

    Bonus: Take a batch script to automate installation of the Git DLL versions on Windows. Just adapt the paths to your Unity install. This is not recommended for non-advanced users, but hey, sharing is caring... (Save this as "install-hlapi-community.cmd" where the 'hlapi-community-edition' folder is and maybe run as admin if you have installed Unity inside Program Files). Otherwise, adjust accordingly.

    Code (csharp):
    1. @echo off
    2. echo Copying base DLLs
    3. copy /v /y .\hlapi-community-edition\Unity-Technologies-networking\Output\UnityEngine.Networking.* "S:\Unity\LTS2017.4.3f1\Editor\Data\UnityExtensions\Unity\Networking"
    4. echo Copying Editor DLLs
    5. copy /v /y .\hlapi-community-edition\Unity-Technologies-networking\Output\Editor\*.* "S:\Unity\LTS2017.4.3f1\Editor\Data\UnityExtensions\Unity\Networking\Editor"
    6. echo Copying Standalone DLLs
    7. copy /v /y .\hlapi-community-edition\Unity-Technologies-networking\Output\Standalone\*.* "S:\Unity\LTS2017.4.3f1\Editor\Data\UnityExtensions\Unity\Networking\Standalone"
    8. echo Copying Weaver DLLs
    9. copy /v /y .\hlapi-community-edition\Unity-Technologies-networking\Output\Weaver\*.* "S:\Unity\LTS2017.4.3f1\Editor\Data\Managed"
    10. echo Done!
    11. pause
    12.  
     
    goldbug likes this.
  30. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Update: uploaded 2017.4 and 2017.4_improvements DLLs based on latest commits, including the OnStartClient fix in both.
    Big thanks to @goldbug @MCoburn for fixing/investigating here.
     
    MCoburn likes this.
  31. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    Hey, glad I could help! I will be giving the OnStartClient fix a good workout during my testing. :)
     
    mischa2k likes this.
  32. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    Oh, by the way... remember how i reported the bug to Unity Tech? Well...
    Literally discarded yet we fixed it. Good job, Unity Tech!
     
  33. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    Unknown Message ID strikes again - but this time it's when the player object is spawned via the Auto Create Player option.

    Problem: OnStartClient() doesn't get fired on a created player prefab if "Auto Create Player" is set in Network Manager.
    Example asset that exhibits this problem: Opsive's Third Person Controller (Network Demo Scene)
    The host does it right, the clients do not!

    After looking into Opsive's code I noticed that they have OnStartClient hooks to register Message Handlers. There's about 5 scripts that control critical things like Inventory, Camera, Input and stuff like that for the kit over the network that sit on the player object. They, of course, are supposed to get the memo but fail to do so.

    In my head, I think the timeline should go:

    Client connects
    OnStartClient fires
    - Client tells server it's coming online and spawns
    - Spawned Player Object Initializes and should fire OnStartClient() hooks too]
    - OnStartClient should fire on the spawned player scripts (but never does)
    Server can see the newly created player entity on the server
    - Client starts erroring out and log fills with messages like "Can't find sync target for netId X" because the scripts have failed
    - Client is stuck in limbo and/or errored state

    I popped my trusty debugging code that just throws a error-level message to see if it would fire inside the scripts on the standalone client but all I got was "Unknown Message ID" and no "OnStartClient() called from <script name>" message emitted.

    I will attempt to replicate this using a generic script for debug purposes so we can stomp these bugs once and for all. #MakeHLAPIGreatAgain2018
     
    Last edited: Jun 30, 2018
    mischa2k likes this.
  34. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    Huh... That's odd. So apparently the code I wrote for the debug script that shouldn't get the memo on a test cube object actually does get the memo. I'm confused here... Does that mean Opsive's code is at fault then or is there some other problem behind the scenes?

    Let me keep investigating this as I swear it wasn't working an hour ago. Maybe some old caches got blown away or something. This is very puzzling.
     
    mischa2k likes this.
  35. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    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
    mischa2k likes this.
  36. mischa2k

    mischa2k

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

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    @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.
     
  38. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Will put it on my list
     
  39. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    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
  40. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    45
    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!
     
  41. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Yes
     
  42. natepacyga

    natepacyga

    Joined:
    Apr 7, 2015
    Posts:
    27
    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.
     
  43. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    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
  44. natepacyga

    natepacyga

    Joined:
    Apr 7, 2015
    Posts:
    27
    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.
     
  45. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    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..
     
  46. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    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?
     
  47. natepacyga

    natepacyga

    Joined:
    Apr 7, 2015
    Posts:
    27
    @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:

  48. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    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!
     
  49. natepacyga

    natepacyga

    Joined:
    Apr 7, 2015
    Posts:
    27
    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
    mischa2k likes this.
  50. natepacyga

    natepacyga

    Joined:
    Apr 7, 2015
    Posts:
    27
    @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 mischa2k like this.