Search Unity

Showcase Mirror - Open Source Networking for Unity

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

  1. joeconstable97

    joeconstable97

    Joined:
    Jul 30, 2013
    Posts:
    50
    Hey, this could very well be user error but I've noticed that the mirror network loop is taking up half of my frame time. Could this be caused perhaps by my possible misuse of mirror's API or is this just the nature of the beast that is mirror?
    Note - I am the host in this scenario with no other clients connected.

    Also, looking forward to that blog post for Mirror II :)

     
  2. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Why is your deep profile button grayed out?
    If you enable it, then you can see more details.
     
  3. joeconstable97

    joeconstable97

    Joined:
    Jul 30, 2013
    Posts:
    50
    Found the issue, thanks very much! Didn't realise that would expand the Network Loop!
     
    mischa2k likes this.
  4. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Mirror II Cmds/Rpcs/TargetRpcs finished!
    17.000 LOC into it, it now has enough features where projects like uMMORPG could already be ported :)
    Early access in ~1 month.
     
    akuno and Willbkool_FPCS like this.
  5. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
  6. Grl-Kiko

    Grl-Kiko

    Joined:
    Mar 16, 2015
    Posts:
    12
    Running a dedicated server within wsl (using tanks demo), clients can't connect to it (it is working fine when running the same exact dedicated server build on native ubuntu). Any ideas why this might be happening?
     
  7. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    I have a question. How does one detect if the server is also a client? That is, whether we're running in "dedicated server" or "host server" mode. A user said we can use:

    if (NetworkServer.active)

    Does that only return true on the client that is a server, or on all clients?

    Thanks,
    -Brian
     
  8. JamesFrowenDev

    JamesFrowenDev

    Joined:
    Oct 10, 2015
    Posts:
    20
    you can check like this:
    Code (CSharp):
    1.  
    2. if (NetworkServer.active && NetworkClient.active)
    3. {
    4.   // do host mode stuff here
    5. }
    NetworkServer.active will be true in both server only and host mode
     
    mischa2k and akuno like this.
  9. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Excellent, thanks!
     
  10. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Mirror 2 progress update.
    Deep profiling to prepare for the CCU test.
    Afterwards documentation, examples and then release :)

    Quite happy with the profiling results so far.
    It's nice that LocalWorldState packing + Delta Compression + Reliability + Send + Recv are all gone from main thread.
    2022-09-01 - Deep Profiling 10k Benchmark with 1 Connection.png
     
    Willbkool_FPCS likes this.
  11. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Mirror 2 Remote Control to prepare for the CCU test.
    Tick rate shows actual / target frequency.
    CPU shows early / late update averages.


    Here's a video:
    https://gyazo.com/1234d93038cbae1ff6e8d39e49dcc449

    Will be very useful for the CCU test, so we can see when the individual threads get full, or how much room there is until actual tick rate drifts below target tick rate.
     
  12. rodrigo_unity487

    rodrigo_unity487

    Joined:
    Feb 23, 2022
    Posts:
    8
    Hi! I hope this is the right place to post this question.

    My team and I are trying to connect Unity Relay (that uses Unity Transport) with Mirror. For this, it seems that we need to implement Mirrors abstract class "Transport". We are looking for any guidance, documentation or samples to help us with this task, but we are not having any luck.

    I asked a question in this other thread about a mysterious sample that theoretically exists but we cannot find it anywhere:
    Connecting Unity Transport (using Unity Relay) with Mirror - Unity Forum

    Any help would be enormously appreciated!
     
  13. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Check out the #epic Transport in our Discord.
    It's a free relay thanks to Epic Online Services' success with Fortnite, and it works well.
     
    rodrigo_unity487 likes this.
  14. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    560
    Does Mirror allowed for host migration?
     
  15. Kaivaan

    Kaivaan

    Joined:
    Jun 7, 2018
    Posts:
    24
    just wondering how do you deal with orchestration is there any providers we can use mirror networking with?
     
  16. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    UNET used to have host migration when we forked it.
    It was always broken and super complex, so we decided to remove it for the sake of stability.
    Probably best to host dedicated servers if you need to.

    Google cloud, AWS, Multiplay etc
     
  17. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Mirror II nearing release!

    Preparing for the CCU test.
    The setup will be built in, for everyone to reproduce.
    Will compare it against original Mirror first.
    Gonna set up some bots + servers this weekend and get the first results.

    Quite happy how it all turned out.
    Much more pleasant to work with than UNET back then.
    Both for stability, performance, code complexity etc.
    Dunno if you guys are gonna like it, but I really am looking forward to using this for my two projects :)
    2022-09-10 - CCU with remote stats.png

    Video:
    https://gyazo.com/c4e639f8a2416cb918690f5c1c6a8491
     
    akuno likes this.
  18. AlphaLulz

    AlphaLulz

    Joined:
    Sep 2, 2019
    Posts:
    51
    Hi, vis2k.

    I'm just wondering if the Mirror dev team is planning on adding a built-in framework for client-side prediction and server reconciliation. It seems like other solutions such as FishNet and Netcode for GameObjects are starting to adopt this as a feature, and it would be really nice for it to come to Mirror as well, as it's one of the most vital features for a smooth and secure multiplayer experience. I and many others would really benefit from this feature being added.

    Is this something you're looking to add in the future? Is this something that might be added with Mirror 2?

    Thanks for your time.
     
    akuno and Quast like this.
  19. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    When we started using UNET for our games, the two main issues stopping us from releasing were stability and scale.
    • Mirror solved stability, and improved scale quite a bit.
    • DOTSNET and now Mirror II exist to solve scale.
    Lack of client side prediction hasn't stopped us from releasing, so it was never a focus.
    For my MMO project, I manually predict movement & skill effects. It's just not built into Mirror.

    I understand it's important for some people.
    But let's solve scale first :)
     
    akuno likes this.
  20. AlphaLulz

    AlphaLulz

    Joined:
    Sep 2, 2019
    Posts:
    51
    Yeah, I understand. Do you feel like it's something that you may add once you have scaling in the place you want it to be, even if that may be a few years in the future? I feel like it would be a good thing to keep in the back of your mind and then work on implementing once you feel like you're happy with the state of current features and stability, and are ready to expand.
     
  21. JamesFrowenDev

    JamesFrowenDev

    Joined:
    Oct 10, 2015
    Posts:
    20
    I've been working on CSP for my fork of mirror. It has all the main parts but I am working on improving and optimizing it before I release it (and probably make a mirror version)
     
    akuno likes this.
  22. AlphaLulz

    AlphaLulz

    Joined:
    Sep 2, 2019
    Posts:
    51
    That would be awesome! I would love to use it once you release it.
     
  23. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Early CCU tests for Mirror II.

    Goal is to compare with original Mirror to see scale & bandwidth improvements.
    Keep in mind that this is not a real game. I'll do a more realistic test for my own game in ~6 months.
    Original Mirror results with same demo coming later this week.



    Setup:
    • 1 x 16 vCPU server machine.
    • 6 x 8-16 vCPU client machines.
    • Unity 2021.3.9, IL2CPP.
    • Linux.
    • Threaded Transport (1 KCP thread).
    • Threaded Broadcaster (10 Broadcaster threads).
    • tickRate: 30 Hz
    • sendRate: 30 Hz
    • 10.000 monsters (red), moving randomly.
    • 0-1000 players (white), moving randomly.

    Results:
    Broadcaster avg. is at around 30% load, indicating that 3 threads would've been enough for 1000 connections.
    Tick rate starts deviating from target 30 Hz at around 800 connections.
    Quite happy that it passed with 0 issues.

    0 connections:
    0 connections.png

    400 connections: 399.png
    399 - server machine - red.png

    1000 connections:
    1000 b.png
    1000 - server machine.png
     
    Last edited: Sep 14, 2022
    Quast, Willbkool_FPCS and akuno like this.
  24. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    CCU Test Mirror classic vs. Mirror II

    400 CCU Mirror classic:

    bandwidth: 7.66 MB/s
    cpu: 31.7 ms
    399.png


    400 CCU Mirror II:
    bandwidth: 1,74 MB/s (4.4x lower)
    cpu: 21.7ms (slows down at 800, allows 2x scale)
    395.png


    Summary:
    4.4x lower bandwidth, 2x higher scale.
    Quite happy with the results, considering it's the first version and very first test :)
     
    Quast likes this.
  25. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    CCU Test Mirror II on dedicated Xeon E-2236 with 6 cores/ 12 threads @ 3.4 GHz (4.8 GHz).

    Google Cloud vCPU server: 40.6 ms
    Dedicated Xeon: 33.8ms

    => 20%
    faster.
    => almost manages to retain target tickRate of 30 Hz.

    So if you were wondering: real dedicated CPUs can be ~20% faster than Google Cloud vCPUs :)





     
    akuno and Quast like this.
  26. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    560
    Good to see the new update. This update should follow with new tutorials for new users.
    Thank you.
     
  27. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Sure.
    The next 1-2 weeks will be focused on documentation + performance tests.
     
    Quast likes this.
  28. Neogene

    Neogene

    Joined:
    Dec 29, 2010
    Posts:
    95
    Hi, I need to have a centralised server which relays the game objects data and forwards to different devices, there is a way to do it (eg: installing the library server app on a remote server)?

    I would like to have only two VR visors watch each other movements and audio chat between them.
     
  29. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    check out the #epic transport in our discord.
    free relay thanks to epic games :)
     
    Neogene likes this.
  30. Juldnarr

    Juldnarr

    Joined:
    Mar 30, 2021
    Posts:
    6
    I updated Mirror to 2022.9.15 and now i'm getting errors. Four "type or namespace name" not found. This is with a fresh project too. Any solutions to this?
     
  31. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Please post the full stack trace + error here. That's what they are made for :)
     
  32. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Update: instead of releasing Mirror II this week, we will backport many of the improvements to Mirror.
    There is too much value that can be added to all the existing projects, Mirror II can wait :)
    Afterwards do another round of CCU tests and re-evaluate.

    Simplifying OnSerialize today, where previously it would need a bool return.
    This was changed to void to a-void confusion and reduce branching for performance.
    Also simplifies weaver generated code:

    2022-09-23 - 14-38-13@2x.png
     
    Last edited: Sep 23, 2022
    akuno and Willbkool_FPCS like this.
  33. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    News: Snapshot Interpolated Timeline
    2022-10-09 - NetworkTime, NetworkTransform timelines merged.png


    Previously, NetworkTime and each(!) NetworkTransform would run on separate timelines.

    Now, everything runs on the same NetworkClient timeline, thanks to our Snapshot Interpolation V2.
    -> Less computations & complexity
    -> All NetworkTransforms are now on the same time, instead of each being on their own time
    -> NetworkTime is now implemented properly via Snapshot Interpolation. This is noticeably more accurate. There's no more big jump in the first 1-3s.

    This is one of those improvements which required months of research & testing, yet most of you won't even notice it other than the fact that it just works :)
     
  34. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Bandwidth optimizations, first round.

    NetworkIdentity.Serialize bandwidth reduced from 1 byte per component index to (roughly) 1 bit per component :)
    https://github.com/vis2k/Mirror/pull/3228

    before / after:


    the removed byte per component:
     
    Last edited: Oct 9, 2022
    Quast likes this.
  35. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Bandwidth optimizations, second round.

    NetworkBehaviour.Serialize 'length' safety reduced from 4 bytes per component to 1 byte per component.

    Error correction remains(!). Never wanted to do the 'barrier' solution, as that loses the built in error correction. Took me several years to think of a better solution, but I think this is quite nice :)

    https://github.com/vis2k/Mirror/pull/3229
     
  36. MinkWorksSimulationTechnologies

    MinkWorksSimulationTechnologies

    Joined:
    Mar 12, 2021
    Posts:
    1
    Anybody know how I could get a legacy version of Mirror compatible with Unity 2019.4?
     
  37. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    You can try one of the older releases on our github releases page.
    Considering to add in the obsolete parts for 2019 support again though. Many people kept asking for it.
     
  38. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Mirror is now compatible with Unity 2019, 2020, 2021 again!
    Get it from Github if you need 2019 / 2020 support today :)
     
    mgear likes this.
  39. alittell42

    alittell42

    Joined:
    Mar 11, 2022
    Posts:
    2
    upload_2022-10-10_10-1-7.png
    Does anyone know how to fix this? I tried importing Mirror into an empty project and was hit with these four error. i tried redownloading and re importing but nothing changed.
     
  40. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    See my above post.
    Mirror is now compatible with 2019/2020 again.
    Download it from github :)
     
  41. alittell42

    alittell42

    Joined:
    Mar 11, 2022
    Posts:
    2
    sweet that solved it, thank you!
     
    mischa2k likes this.
  42. Clashman

    Clashman

    Joined:
    Feb 18, 2019
    Posts:
    53
    Hi !

    I'm currently using Mirror Networking to make a multiplayer game. I have a scene when players are all connected, they can choose their characters and set the ready. If all players are ready, I change current scene to arena scene using MyNetworkManager.ServerChangeScene(arenaSceneName). This method sets all player clients as not ready. But After the scene was loaded, my player client is no longer connected to my host and I don't know why.

    Can you help me please ?

    Thanks a lot for answers.
     
  43. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Please check out the build in scene examples.
    I think MrGadget made one that does just that.
     
  44. Clashman

    Clashman

    Joined:
    Feb 18, 2019
    Posts:
    53
    I didn't find it.
     
  45. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    SyncDirection released.

    NetworkBehaviour OnSerialize can now be directed either from server to client, or from client to server.
    For example, this will allow us develop NetworkTransform V3 without Rpc/Cmd call overhead for client authority, where previously OnSerialize couldn't be used since it was only going in one direction :)

    Note this means that any component can now run in what's known as "client authority" mode. However, you can still validate in the server's OnDeserialize, which is why we named it "SyncDirection" instead of "ClientAuthority".

    2022-10-18 - SyncDirection.png
     
  46. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Quast likes this.
  47. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Preparing the upgrade path to NetworkTransform V3.
    Trying to be very careful so nothing breaks in your projects.

    • NetworkTransformChild will be obsolete. use NT with public .target instead
    • .clientAuthority will be obsolete. set SyncDirection to ClientToServer instead.
    Note that everything still works even if you ignore the warnings.
    But eventually the old stuff will be removed :)
     
  48. Develop-Ahead

    Develop-Ahead

    Joined:
    Jun 25, 2015
    Posts:
    4
    I update Mirror 2022.9.15 and found Error

    Assets\Mirror\Runtime\NetworkReaderExtensions.cs(156,17): error CS0246: The type or namespace name 'ReadOnlySpan<>' could not be found (are you missing a using directive or an assembly reference?)

    Assets\Mirror\Runtime\NetworkWriterExtensions.cs(188,37): error CS0246: The type or namespace name 'Span<>' could not be found (are you missing a using directive or an assembly reference?)

    Assets\Mirror\Runtime\NetworkWriterExtensions.cs(188,19): error CS1061: 'Guid' does not contain a definition for 'TryWriteBytes' and no accessible extension method 'TryWriteBytes' accepting a first argument of type 'Guid' could be found (are you missing a using directive or an assembly reference?)

    My current Unity Editor 2020.3.26f1
     
  49. Clashman

    Clashman

    Joined:
    Feb 18, 2019
    Posts:
    53
    I succeed to make the playerclient connected when the scene change. Now, the player prefab for my client is in host view but not in the corresponding client view. Do someone can tell me why ?
     
  50. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Please try latest Mirror from Github. We added 2019 support again last week or so.