Search Unity

Unity Multiplayer Mirror - Networking for Unity (UNET Replacement)

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

  1. Che4Cuba

    Che4Cuba

    Joined:
    Jan 17, 2017
    Posts:
    31
    Keep going vis. You're doing well. Everyday we move closer to multiple scenes with a fixed HLAPI. I'm glad I could bring the Readbyte but to your attention and am happy that you have it working. Cannot wait until scenes are done, everyone is extremely pleased with what you have done so far.
     
    vis2k likes this.
  2. rob_vld

    rob_vld

    Joined:
    Jul 9, 2013
    Posts:
    158
    Will this work using a standalone authoritative server setup with latency correction(interpolation/extrapolation)?
     
  3. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    Progress: still playing around with different NetworkTransform interpolation methods. I found one that I really like, here is a gif again: https://gyazo.com/6f258fd69cc405b66059812abc0b8879

    The gray dot is the ghost, which represents the last OnDeserialize call that the client received. The client follows that ghost pretty well and smoothly. This is a 500ms send interval by the way, which was used by an MMO I played 8 years ago. In 2017, we could get away with 250ms or 100ms and get even better results.

    Thanks, will do.

    If this works with the default HLAPI then it works with HLAPI Pro too.
     
    Last edited: Aug 3, 2017
  4. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151

    I get 300 ms with Unet limited at 4k bandwith on my position synchronization.
    You can get 150 ms or 100 ms with a hight sending rate :)

    If you can get a better synchronization than playing the past in 300ms, I am curious :p.
    (Good luck to synchronize "when" 300ms is ... I rewrote all the NetworkManager to have mine which suit me 100% for problems like that :D).
     
  5. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,133
    Well the least you can get is dependand on your sendrate. If you send once every 10 seconds. The least you can have is 100ms. (That's the last two). If you send 20 times a second. The least is 50ms (That is if you only interpolate and don't do any extrapolation)
     
    Last edited: Aug 3, 2017
  6. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    Sorry I might have explained this wrong. We can of course use 100ms or 50ms send rates easily. What I meant was that 8 years ago that MMO I played used 500ms to minimize bandwidth. But these days everything is 10x as fast and so even 100ms won't be a big deal anymore.
     
  7. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,133
    Correct, And even 100 ms is really low for realtime games. Usualy 50 - 75 is the norm there. (15-20 sends per second). But with my post above I was speaking about Interpolation latency. But sendrate is fairly game specific
     
  8. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    15-20 send per second doesn't mean 50-70 ms.

    I synchronize at 15 send per second, on an unreliable channel (better for this things I rode...). With Unet you get 50-75 ms minimum (optic fiber or not, it's Unet Server ...) + the delay between your post and the sending. For a reason the delay is very very hight, i can't get better than say..200 ms (for pure smooth movement). So I secure to 300 ms.

    With an highter frameRate (40-60) you get your 100 ms, but you reach the 4k bandwidth limit (The Command/RPC with a Vector2 and the time when you send it)...

    And you have to synchronize "when" is 300ms between client and server and others clients. It's a mess that ServerTimeStamp is not synchronize between all clients... you have to synchronize it by yourself... Or say me if there is an other way to do it :)

    Extrapolation is great yes, but when you have a character which can jump, use tools to change movement etc.. I don't know how to do that ^^ .
     
    Last edited: Aug 4, 2017
  9. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    Good morning everyone. Going to work on the NetworkTransform's rotation interpolation today. Hopefully to release a test version soon.

    UNET always waits for a few more other packets before it actually starts sending them out. You can modify that in the global config's send delay.
     
    xVergilx likes this.
  10. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    Progress: rotation synchronization + smooth interpolation: https://gyazo.com/176e66e3cfb9c535671e155645f3f2f6
    Note that the little twitch happens when going from 360 degree to 0 degree, where the interpolation goes all the way backwards. A better solution will come later, what matter is that the networking part works pretty well.
     
    chiapet1021 and xVergilx like this.
  11. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    chiapet1021 and xVergilx like this.
  12. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    Progress: finished Rigidbody movement and rotations. Working on rotation compression modes now:
    2017-08-04_networktransform_b_lots.png

    None: 12 byte
    Some: 6 byte
    Much: 3 byte
    Lots: 2 byte (which is kinda funny if you do the math).

    For comparison, the old NetworkTransform's compression used:
    None: 12 byte for XYZ
    Low: 6 byte for XYZ
    High: 6 byte for XYZ

    Will do some more testing tomorrow and then release the next version with the new NetworkTransform component.
     
    Last edited: Aug 4, 2017
  13. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    Update: NetworkTransform finished and released. I uploaded the DLLs to the stable version in the first post.
    • [2017-08-05] NetworkTransform reimplemented from scratch
      • Problem: NetworkTransform was bloated with lots of components, all together 2144 lines of code. No interpolation. No NavMeshAgent consideration. High and Low compression modes did the same. No distinction between Kinematic and nonKinematic Rigidbodies. Too many computations.
      • Solution: reimplemented it from scratch. 300 lines of clean and simple code. Transform/Rigidbody2D/Rigidbody3D/NavMeshAgent support (including Kinematic Rigidbodies). Interpolation. 4 compression modes, able to squeeze a Quaternion into 2 bytes and still work. Teleport detection. Great Gizmo makes it easy to debug.

    I tested it in my uMMORPG project and it works really well. If anyone finds issues, please let me know. The code is worth looking at too, the Quaternion to 2 byte compression is kinda interesting.

    And here's a screenshot of the Gizmo, which turns out to be very useful for debugging:
    2017-08-05_networktransform_gizmo.png
    The bright one is the latest DeSerialized data. The dark one is the one before that. The component always interpolates between them.

    Here is a video of Teleport Detection in action:
    https://gyazo.com/d7b6b3a3f05c32e3b0970285398a0c9e
    I click behind the fence, the NavMeshAgent moves there on the server (see bright gizmo), but the Client's send interval is too huge to notice the walk around the fence. Client realizes that the destination can't be reached a short time and then teleports there.
     
    Last edited: Aug 5, 2017
    Saishy, Possum1 and mons00n like this.
  14. Possum1

    Possum1

    Joined:
    May 19, 2017
    Posts:
    3
    Keep the improvements coming. Someone at unity really needs to take notice of this project.
     
    Kaivaan and vis2k like this.
  15. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    73
    Woa that is great!

    If you get a NetworkAnimation working I'm more than ready to jump on this!!!
     
    vis2k likes this.
  16. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    Progress: I set up a HLAPI Pro Patreon page instead for those who feel like contributing. Should be better than a commercial license or a paid Asset.

    Will do.

    Thank you. I am not sure if anyone should even use NetworkAnimator. I fiund it more useful to synchronize the current state and then do animations on the client. That works really well in uMMORPG, uMOBA etc.
     
    Last edited: Aug 5, 2017
    runningbird likes this.
  17. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    219
    I think a lot of people would use the NetworkAnimator if it wasn't so poorly optimized. I find the idea of syncing the animation parameters extremely useful. I had to write my own to reduce GCallocs.
     
    Saishy likes this.
  18. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    73
    A question, do your network transform know when not to send it's position? As in, it will not use bandwidth if the object does not move, right? (or if it moved but came back to the exact same space before the next packet time)

    Also, I went to pledge to your patreon but it's saying "per post"??? Do that means every time you post anything I pay that amount? DDD:
    Why not per month like a common patreon?
     
  19. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    So for NetworkAnimator it's just the optimization, or are there really features that do not work?

    Not yet. This can be done easily with a dirty bit later, but I want to leave this first version out there for a few days to see if anyone finds any bugs before I add more to it.

    I never used patreon before, I didn't select anything about posts anywhere. It works per-month as far as I know, but I will look in the settings if I find something related.
    Edit: found it, fixed it. Sorry about that.
     
    Saishy likes this.
  20. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    73
    Thanks! Sorry for the low pledge but it's what I can do without being a burden on my current patreon too :~

    Also something that just ticked me now, with the current installation it means my git repository would not be able to be ready to use right? Since it needs file changes in the unity application itself :c
     
    vis2k likes this.
  21. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    Thanks a lot!
    What do you mean with your git repository being ready to use?

    If you want to use HLAPI Pro in your project then all you have to do is replace the DLL files in your Unity installation, see usage guide on the first page. Right now there's no way to put the Scripts into a Unity project like with Asset Store stuff, because parts of the NetworkTransport API are 'internal'. The source code repository is mainly there for you to see what happened lately.
     
  22. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    73
    Yeah that was it.

    Because I have freelancers working with me, and I would just give them access to the git and they could work.
    But I wonder if having them mess with their unity installation would put them off :c
     
  23. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    Your project should still run even if they use the built in HLAPI. I really want HLAPI Pro to be a drop-in replacement that just makes it better without breaking anything. They don't have to use it if they don't want to - even though it does make debugging easier, see ReadString bug error message improvement.
     
    Saishy likes this.
  24. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    73
    !!! Incredible :O

    Also, shared this post on the indie game developers server <3
     
    vis2k likes this.
  25. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    73
    Does your GetRemoteDelayTimeMS work on client? Current one is broken :c

    Edit: Also another thing, in the instruction you say to move the weaver dll, but only the dll? I'm leaving the mdb in the weaver folder...
     
    Last edited: Aug 6, 2017
  26. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    219
    It does a ton of per frame gc allocs. Also if you have an parameter controlled by a curve it constantly gives you a warning about that even if you don't select that particular parameter to be synchronized.
     
    vis2k likes this.
  27. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    73
    When I changed to your hlapi my main menu broke, the clients don't show the menu and when the host selects a class I receive this error:

    Found no behaviour for incoming [ClientRpc:InvokeRpcRpcClientChooseClass] on PlayerController(Clone) (UnityEngine.GameObject), the server and client should have the same NetworkBehaviour instances [netId=7].
    UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
     
  28. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    Did you rebuild your server/client too? It has to use the DLL files as well.

    Didn't touch that part yet, will put it on my list.
     
    Last edited: Aug 6, 2017
  29. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    Progress:
    • [2017-08-06] NetworkManagerHUD via GUILayout
      • Problem: NetworkManagerHUD tried to emulate GUILayout with manual yspace increasing which resulted in way too much code that was way too hard to look at and debug. It also had no background, so white Labels often weren't readable if the 3D world behind it was not dark.
      • Solution: replaced GUI with GUILayout. Saves 50 lines of code. Includes neat little background box.
    This update isn't too exciting, but it bothered me a lot so it had to be done.
     

    Attached Files:

  30. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    73
    I don't have a "server", it's a client to client game. So I tested with a build and the editor like always.


    Wait, but what about the mdb file???
     
  31. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    You can ignore the mdb file.

    You can try the latest version that I just uploaded, I added a small error message in case the assetId isn't assigned - it should never happen, but just to be sure. Other than that see if it happens with the original HLAPI too.
     
  32. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    73
    Bug persists.

    Does not happen with original HLAPI

    Edit: Also, returning to original HLAPI made all network transform broke as position is not being synced anymore.
     
    Last edited: Aug 6, 2017
  33. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    So just to be sure, is this what you do:
    • Download HLAPI Pro
    • Replace Unity DLLs
    • Open Unity Editor
    • Build your project as project.exe
    • Start project.exe and connect to it from another project.exe or from the Editor
    Because it sounds like what would happen if they use different HLAPI versions.
     
  34. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    73
    Yes I'm doing that.

    And original position sync still broken :c

    Update: Resetting the networktransform component fixes, so it seems the HLAPI Pro and HLAPI are not interchangeable at will :2

    Edit2: It seems your networktransform don't work the same way as the default one, the default one syncs from the client that has authority and not from the server.
    So their uses are basically different, you should at least have a way to toggle if it's server only or from owner.

    Also noticed something strange, I'm testing it from my own computer to my own computer and you can clearly see some hipcups in the movement.

    https://gfycat.com/FatBlaringBilby
    (Edit3: Ah sorry, it seems as the webm is recorded in a low fps you can't actually see it that much...)

    The default one is really bad, but never showed this in a 0 ping environment, so I'm guessing it's something on the interpolation or the speed guessing?
     
    Last edited: Aug 7, 2017
  35. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    Can you send me your project to debug? Otherwise I can also send you previous versions of HLAPI pro for you to test, so that I know when the issue started.

    About NetworkTransform: local authority isn't supported yet, will add that very soon though!

    Unity probably loses the serialization data of the old DLL if you swap in the new one. But with a reset it should work fine. The code is at least compatible.
     
  36. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    73
  37. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    Progress: looking at NetworkTransform local player authority now. I use it in my VOXL project, so that will be a good test setup.

    You could upload it somewhere and then send me the link. Would be best if you simplify it as much as possible if you have the time to do that.

    Will bookmark those.
     
  38. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    Update: next version uploaded, see link in first post.

    Removed the AssetId replacement, thanks to @Saishy for reporting the issue. The built in one was perfectly fine, I completely missed that it uses not the asset path but the asset path to GUID.

    Anyway, back to NetworkTransform!
     
  39. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    522
    NetworkTransform doesn't work correctly with my transforms. I'm just unable to move a character on the client side, but everything works fine on the host. The default HLAPI NetworkTransform works without this issue.
     
  40. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    Do you use local player authority? I am implementing support for that right now.
     
  41. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    522
    Yep.

    Oh, I didn't read your previous messages, now I see where the problem is... :oops:
     
    Last edited: Aug 7, 2017
  42. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    Update: next version released, now with NetworkTransform local authority support. Tested it in uMMORPG and VOXL, works great. Let me know if you guys have any issues and thanks everyone for reporting bugs!
     
  43. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    522
    Good job! So far I have only one issue that interpolation doesn't work on the host.
     
  44. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    With the new version you mean?
     
  45. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    522
    Yep. On the client interpolation works fine.
     
  46. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    Thanks for letting me know, will take a look.
     
  47. notseanr

    notseanr

    Joined:
    Jan 15, 2016
    Posts:
    22
    Also NetworkReader and NetworkWriter are limited to 64K element size arrays because the array size is a 16-bit integer. This is annoying if using them for serializing to large buffers, or to files. Should fix that to be a 32-bit integer...
     
  48. akuno

    akuno

    Joined:
    Dec 14, 2015
    Posts:
    34
    This is a wet dream becoming real.

    Vis2k is doing Unity's job, Unity should pay him for that.

    This guy has even proven himself as an AssetStore developer. Unity should hire him, even for a Remote position, in case he doesnt want to move.
     
  49. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,218
    Update: next version uploaded with NetworkTransform host mode interpolation fix for local authority cases. Thanks for reporting the bug @nxrighthere .

    Will put it on my list.

    Thanks for the trust.
     
    akuno likes this.
  50. Saishy

    Saishy

    Joined:
    Jun 3, 2010
    Posts:
    73
    I didn't know you could write messages directly without a class, I'm learning so much from your code!

    Code (csharp):
    1.  
    2. // send message to server
    3. NetworkWriter writer = new NetworkWriter();
    4. writer.StartMessage(MsgType.LocalPlayerTransform);
    5. writer.Write(netId);
    6. SerializeIntoWriter(writer, true);
    7. writer.FinishMessage();
    8. connectionToServer.SendWriter(writer, GetNetworkChannel());
    9.