Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Showcase Mirror - Open Source Networking for Unity

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

  1. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Local player means that this object is the player that you control. It shouldn't be false if this is your local player. It might be false for other players that you connect to the server with. Are you sure it wasn't just another player?

    Thanks, I never got any null issues with connectionToServer, but I believe you and since the original one does it too, I will change it.
     
  2. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    79
    Nope, I'm actually playing alone lol

    You can see here: http://i.imgur.com/33SeUgi.png
    I'm a client, I has authority, and I has localplayer authority, but I'm not a localplayer (who am I?)

    The one from the original works fine in all cases so I don't see a reason to change it anyway.
     
  3. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Can you strip down your project and send me a simple version to look at later? Might be the next UNET bug right there.

    Also before I change to readyConnection - does it help if you check if connectionToServer != null in the original code before sending?
     
  4. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    79
    Depends, can you get a better channel to talk than the unity forums? xD
    Also wanna talk something that might be a new bug in your release.
     
  5. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Uploaded another version with connectionToServer != null check and removed debug messages.
    Let's use this thread a while longer until this grows a bit. Will setup a discord server later.
     
  6. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Update:
    • [2017-08-08] Nondeterministic SceneID bug fixed
      • Problem: OnPostProcessScene assigned SceneIDs based on the order of FindObjectsOfType<NetworkIdentity>(). The order is not guaranteed, which resulted in different SceneIDs each time the Editor restarts. Reconnecting to a build after restarting the Editor would then cause bugs where UNET tried to serialize the wrong objects, often causing 'ReadString out of range' errors etc.
      • Solution: SceneIDs are now based on the recursive sibling index in the Hierarchy. This doesn't change after restarting, only when manually changing the Hierarchy.
    This was the most critical UNET bug that I am aware of. A showstopper for many developers, causing random ReadString/ReadBytes ouf range exceptions without knowing why. I highly recommend everyone here to use the new DLL that I just uploaded, as this bug is not good for your sanity.

    If you like it, consider supporting HLAPI Pro development.
     
    Last edited: Aug 8, 2017
  7. camta005

    camta005

    Joined:
    Dec 16, 2016
    Posts:
    320
    Agreed :p
     
    mischa2k likes this.
  8. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    I second people saying Unity should hire you. This is the biggest step forward in UNET since its release.
     
    akuno, mischa2k and xVergilx like this.
  9. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    I agree. But, it's not a step, it's a HUUUUUUUUUUUUUUGE LEAP. That single bugfix of sceneId's is priceless.
     
    akuno, Stormy102 and mischa2k like this.
  10. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Thanks guys. My set of projects to test it with is limited, so please let me know if you encounter errors.
     
  11. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Last edited: Aug 8, 2017
    chiapet1021 likes this.
  12. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    It's a shame that it requires replacing core Unity files - makes it sadly virtually unusable for our main project :(
     
  13. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Make a editor script?
     
  14. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Will put it on my list.

    There are benefits to just having to replace a DLL. No code modifications necessary and (in theory) you should be able to swap it out with the original HLAPI DLLs again any time soon.

    As long as some NetworkTransform classes are internal that's the only option anyway.
     
  15. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Update: one of my uMMORPG customers found another issue with SceneIDs. I uploaded the last stable version and linked it in the first post. Will provide a stable and a experimental version from now on, so that the experimental one can be tested by as many people as possible before replacing the stable version. Less stress for everyone involved.
     
  16. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    79
    NetworkTransform?? The only thing internal in that one is the RegisterHandle isn't it? Did you do a typo?

    Also I don't think anyone cares about no code modifications and the swap.
    Like, it's cool and all, but swapping actually brings a lot of problems with serialization in the table.
    And code modifications are really simple, people who are doing networking "should" have higher average programming abilities. If not... well they are not going too far anyway :2c
     
    Last edited: Aug 9, 2017
  17. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
  18. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Progress: found the issue for the other sceneId bug. Implemented a solution yesterday night, going to test it today and then hopefully release later.

    Sorry, NetworkTransport of course!

    Didn't they say they fixed it in a future version?
     
    xVergilx likes this.
  19. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    Problem with replacing a DLL is that our team uses Git. And every time we upgrade Unity (which is pretty regularly) we have to change the DLL :( It's still good for my own tinkering with Unity tho - I can always do experimental builds with HLAPI Pro but its not possible for using in a production environment.
     
  20. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Welp, it's 2017.1, still not signs of fixes. So it's actually the same behaviour. Also last post from Unity dev:
    They literally don't know how to fix it, since nobody understands HLAPI there. ._.
     
  21. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    79
    Same reason I'm not using :2
     
    Stormy102 likes this.
  22. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Can't you write a Editor script? @vis2k if you make a static download page that always contains the latest version. Then you could easily write a editor script that checks for updates every once in a while. And if there is a new one. You download it and replace it (From the editor script). That's assuming you can write to the file while unity is running.
     
  23. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    Sounds like a decent idea (kind of like a separate package?) but I think they're all in use when Unity is running. Might be worth looking into @vis2k?
     
  24. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Just tried, I can access it if I have the editor open. I just need admin rights. Atleast on Windows.
     
    Stormy102 likes this.
  25. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    79
    The people who work with other projects too would kill me lol
     
  26. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    HLAPI is so bad at all.

    NetworkManager need to be inherited from and you need to replace virtual function... Ok it's not the feeling of all the rest of Unity...

    Replaced it by my own HLAPI with use of delegate was what strongly deliver all potential of the LLAPI.

    Same things for Matchmaking included in the NetworkManager ... cut in two differents scripts was better : one for connecting to party (LOCAL, LAN, ONLINE) , one for finding party (Online and LAN. LAN was not possible with the current HLAPI but the LLAPI permit it...)

    And NetworkTransform : totally rewritten including LAN/Online switch for different bandwidth utilization.

    Same for sceneChange : what if clients have to change scene with a load screen ? It's not possible because the server tell nothing to client except that the scene changed.
    What if they have to wait the server before entering to the scene. HLAPI : server change scene and AFTER clients are tell to change scene : you have double the time needed for a client to change the scene : Good Job. You can't even load the scene at 90% on client and wait the server for complete the loading...

    AnimatorSync is a bad coding practice. Most of the time you drive animation by an other stateMachine and/or all animations states don't need to be synchronized (because it transit automaticly from animation to animation ...).


    My opinion : ok it's cool to repair the HLAPI, but you can do better in rewritting it from scratch and only with the LLAPI.
    HLAPI is for beginner, you can't do complex games with that. I don't know how you can do complex network things with few scripts like the HLAPI provide to you.

    That's my opinion, I follow you to see how far the job goes =)
     
  27. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Well, it was an example of how high level library should be written. A bad example.

    Too bad nobody actually told us that it was an example at the time our project has started. Only like 3 years after, Unity dev's mentioned that.
     
    Last edited: Aug 9, 2017
  28. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    I agree, it should have been alot clearer. However, I think it's a good example. If per say a large studio wants to make a own HLAPI for their devs to make networked code easier. Then I can see that being an excelent example.

    And also, I feel the same that I wish I would have been told earlier. Our title is being rewritten to LLAPI. We have only about a week left on that Deadline and it's going really smooth. Fairly straight forward process. No big isuses. Just time consuming.
     
    mischa2k likes this.
  29. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Progress: hi guys, nice to see so much activity here! Been researching the scene id issue all day. I am coming very close to a solution that works really well and is almost no change from the original code.

    Well he's the LLAPI developer so can't take that negatively.
    I am pretty sure I can fix it, will look into it after the readstring fix.

    Yes planned for the future. Fixes first, then the 'comfort' features later.

    I thought so too. But to be honest, the more I look into the HLAPI the more I respect the work. This must have been a pain to develop, the Weaver alone is pretty crazy. The architecture is really good. Just feels overly complicated here and there, but that can be improved upon.

    See my above answer. It might have been meant as an example, but it's way too well thought out for 'just an example'. The Weaver alone is not something that you quickly develop for an example, this is really difficult to do and really useful to have when it comes to performance.

    The HLAPI's power is that you can now develop multiplayer games that would've been too big otherwise. For example, my uMMORPG project uses only 5000 lines of code thanks to UNET. My previous C++ MMO project had 10% of the features and 50.000 lines of code.

    If I were to develop a high level networking solution on top of the LLAPI, I would use exactly the same architecture with client&server in one project, syncvars, commands, etc. It just needs cleanup and some more attention, that's all.
     
  30. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    There are lots of really neat things about the HLAPI. I love the [Command] [ClientRPC] and [ClientCallback] stuff - really nicely done, along with NetworkMessages and the ability to serialize raw data via OnSerialize/OnDeserialize. But there are several flaws, and many hoops, such as having to initialise the NetworkTransport before creating a server and the over-complex nature of some elements.

    TL;DR Don't execute the HLAPI yet, it's not beyond saving :)
     
    mischa2k likes this.
  31. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Update: Experimental version added to first post. It has the new sceneId bug fix. Instead of assigning the sibling index path hash as SceneID, it now sorts the FindObjectsOfType result by the sibling index path. This way it's robust against DontDestroyOnLoad messing with the indices and it's the least invasive fix.

    I tested all the previous scenarios and it works. If you have a minute, please test it in your project and let me know if all the spawning works fine - even after restarting the Editor and connecting to a build again.
     
    Last edited: Aug 10, 2017
    Stormy102 likes this.
  32. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    @aabramychev Is there any possibility of merging some of these changes into official UNET at some point in the future? I know you're the LLAPI guy, but you are the only person who seems to routinely respond :p
     
    akuno likes this.
  33. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Update: uploaded a new experimental version, I am sure you guys will like this one:
    • [2017-08-10] Fixed "ServerDisconnected due to error: Timeout" bug.
      • Problem: NetworkManager.OnServerDisconnect throws an error each time a client times out. A timeout isn't really worth throwing an error, since it happens all the time.
      • Solution: NetworkManager.OnServerDisconnect only throws errors if the cause is not 'Ok' and not 'Timeout'. Also improved the log message because it sounded like the server disconnected itself, even though a client disconnected.
      • upload_2017-8-10_12-58-24.png
     
    Stormy102, camta005 and xVergilx like this.
  34. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    Command and Rpc work great. Just you can't have the same script multiple time on the same object .. command/rpc will fail by taking the first one.

    After this, you can't keep a gameObject with networkIdentity alive when disconnecting from server when you have authority on it... this is a problem too. The same things appear when you locally play your game and want to connect to a server without changing scene : you can't keep your character and all networked object... It's a problem when you want a very smooth game.

    If you have a solution for the last one .. I would take it :)
     
  35. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    79
    I just got that bug with [command] and [clientrpc] where if you have multiple classes that inherit from the same it don't know which one to call xD
     
  36. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    If you're serious about your networking, I don't think many people will use the NetworkManager. We literally ripped the code straight from Bitbucket and used that as the basis for our NetworkManager. The original code is virtually unrecognisable now... added comments and stripped the crap like WebSockets and all the different Start* functions as well as adding our own custom stuff.
     
  37. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Well, we surely do. Not that we should. Maybe same should be done for our project.
     
    nxrighthere likes this.
  38. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Due to the Ease of use of the HLAPI it attracts many non experianced developers to create multiplayer games. That's when the NetworkManager is great.
    It's kindof the same deal with the NetworkTransform. It's great to just prototype with. But if you want something for a real project that's going to market. You probably want to rewrite your own. I find that the HLAPI is a great tool for developing. But that the HLAPI components are just good for Prototyping and learning.
     
    Stormy102 and Deleted User like this.
  39. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    That's a HLAPI bug, right? Not something that only happens with HLAPI Pro?
     
  40. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    79
    yep
     
  41. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    You should - we were able to add in our own authentication, version checking and the integrity of certain core files. Means that networking is safe from different versions and we can have password-protected servers.
     
  42. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    Password protection are in the HLAPI no ? I used that for my little small bit project.
    Same for version you can send it to matchmaking and disable match not in the same version.

    What you can't do, and it's not super, it's to check a whatever current online version of your game and don't permit client to join game.
     
  43. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Update: uploaded a new experimental version:
    • [2017-08-11] Statically cached Messages removed.
      • Problem: the HLAPI is complicated enough as it is, caching messages statically makes the code so complicated that it's hardly worth an extra allocation. Many of the cached messages are only sent once per client anyway.
      • Solution: messages like 'new CRCMessage' are created when they are needed by the message handler. Less global state, less complexity, cleaner code, easier to debug and to understand.

    "Make it work, then make it fast" - the HLAPI is fast, but it doesn't work too well. All those micro optimizations are useless as long as the HLAPI is full of bugs and too complex to debug. The smart thing to do is to simplify where ever possible so we end up with a code base that can be maintained and understood without going insane.

    Related:
     
    Kaivaan, akuno, Saishy and 3 others like this.
  44. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    That Code Quality Measurement :D
     
  45. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    Hi,

    First, apologies if the question is too noobish. I am still starting out in networking.

    I just came across this thread while looking around for networking tutorials. Originally I found HLAPI to be really cool and easy to handle. Since I had little knowledge of networking, I didn't know it wasn't server authoritative by default (NetworkTransform) so I stopped learning it. Now reading through the threads, I get the feeling that isn't the case with HALPI Pro. Does the new NetworkTransform account for getting the position from the server rather than sending its position to the server?

    Thanks for your reply.
     
  46. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    NetworkTransform supports server and client authority now, no problem!
     
  47. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Update: uploaded the next experimental version.
    • [2017-08-12] Simplified public fields
      • Problem: private variables were wrapped with public get+set properties in many cases, when using a public variable would give the exact same result with less code.
      • Solution: replaced some public get/set properties with public variables. Also replaced some properties with get + private set to keep things simple.
    This one isn't too exciting either, but prepares for the next wave of fixes.

    HLAPI Pro is almost 2000 lines of code shorter now, here is the statistic:
    • HLAPI: 21060 LOC
    • HLAPI Pro: 19220 LOC
     
    camta005 and Stormy102 like this.
  48. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    79
    Oh wanted to ask, are you making nonalloc versions of the readbytes? The HLAPI seems to allocate a new byte array every time it wants to read something :2
     
    Stormy102 likes this.
  49. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Not planned at the moment, but I am currently researching something related. I am converting NetworkReader/Writer back to C#'s built-in MemoryStream instead of NetworkBuffer. Would be one less point of failure, since we can pretty much assume that the built-in one won't have any bugs, ever. Also less code to worry about and to maintain, which is good seeing how that's the main problem of HLAPI.

    If we are lucky then it's even faster than the custom NetworkBuffer, will test that soon. The comment in the HLAPI code says that NetworkBuffer is only used to avoid allocations within MemoryStream - but MemoryStream buffer size can be configured, so that should be just fine (in theory).

    Will know more soon.

    If this works out as planned, then I might even wrap it with BinaryWriter/Reader and use the built-in write/read string version. Perhaps this allocates less memory and answers your question, not sure yet.
     
    Last edited: Aug 12, 2017
    Saishy and Stormy102 like this.
  50. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    NetworkIdentity.clientAuthorityOwner is null on client so you can't have access, on client, to the connection associated to a networkIdentity (because all others variables related to connection are server only)

    It seems to be a bug, the documentation didn't say it's only available on server...