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,347
    Remote Statistics released!
    - Add a NetworkStatistics component to your NetworkManager
    - Add a RemoteStatistics component to your player
    - Connect the client to your server
    - Press F11 on the client, log in with the password from remote_statistics.txt

    Additionally, the CCU Test Demo is now available in the Examples folder.
    This ensures that all our tests are easily reproducible by everyone :)

     
    Last edited: Oct 31, 2022
  2. Clashman

    Clashman

    Joined:
    Feb 18, 2019
    Posts:
    53
    Hello !
    I'm using a syncdictionary but it's not sync... I can add things in the dictionary only in server side and on client side, I can't see the added things by the server. Do you know why ?
     
  3. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    CCU tests 2022-10 :eek:
    Instead of releasing Mirror II, we are backporting improvements to current Mirror for free.
    There have been many smaller CPU & Bandwidth improvements during Sept/October.
    Additionally, NetworkTransform V3 is ready for testing.
    • [Rpc]/[Cmd] syncs were moved to the new bidirectional OnSerialize
    • Sending over reliable allows us to apply manual delta compression in OnSerialize.

    We are testing 400 CCU on a 16 vCPU Google Cloud instance.

    Below is a comparison between Mirror II, Mirror before, and Mirror after the latest improvements.
    • 3.7x bandwidth reduction: 7.66 MB/s to 2.04 MB/s
    • 18.7% performance improvement: 32 ms to 26 ms (or 20ms over Telepathy)
    2022-11-01 - 12-20-31@2x.png
    Note that current NetworkTransform is unreliable, while NetworkTransform V3 is reliable.
    It's a trade-off between a small increase in latency, vs. a significant decrease in bandwidth.
    We want to optimize the unreliable NT first, before we decide which one to choose (or offer both).

    Also note that the 18.7% performance improvement is already live on Github either way.

    Disclaimer:
    The numbers apply only to our CCU demo, and the goal is to compare results over time.
    It does not mean every game can support 400+ CCU.
    The CCU demo is publicly available, for everyone to reproduce.
    The test runs on google cloud. Dedicated servers will be 10-20% faster.

    Next steps:
    - Threaded KCP to achieve the same performance as Telepathy (TCP)
    - Try 600/800/1000 CCU
    - Improve unreliable NetworkTransform

    Please consider to support Mirror with your recent bandwidth savings :)

    400 - removed IP.png
     
    Last edited: Nov 1, 2022
    kmowers likes this.
  4. Varga87

    Varga87

    Joined:
    Jun 3, 2019
    Posts:
    6
    I have a mirror question. I'm tying to invoke an event from my stateMachine witch is a NetworkBehaviour class to a subscribed State class, but I can't get it to work. Isn't this possible?

    Code (CSharp):
    1. public class StateMachine : NetworkBehaviour {
    2.    public event Action PlayerDetectedEvent;
    3.  
    4.    private void OnTriggerEnter(Collider other)
    5.    {
    6.     Debug.Log("Invoke event");
    7.     PlayerDetectedEvent?.Invoke();
    8.     }
    9. }
    10.  
    11. public class IdleState : State
    12. {
    13.     public override void Enter() {
    14.         stateMachine.PlayerDetectedEvent += OnPlayerDetection;
    15.     }
    16.  
    17.     public override void Exit() {
    18.         stateMachine.PlayerDetectedEvent -= OnPlayerDetection;
    19.     }
    20.  
    21.     private void OnPlayerDetection() {
    22.         Debug.Log("Switch state");
    23.     }
    24. }
    This is what the relevant code looks like. Enter() and Exit() are run when switching in and out of the state (code not featured). I get to the first log "Invoke event", but not "Switch state".
     
  5. Varga87

    Varga87

    Joined:
    Jun 3, 2019
    Posts:
    6
    Never mind I found the error myself. My state was never run correctly!
     
    mischa2k likes this.
  6. micpatmc

    micpatmc

    Joined:
    Apr 2, 2020
    Posts:
    1
    upload_2022-11-4_14-3-39.png
    Hello, anytime I have two players on a server, and I go from the lobby to the game scene, it seems that on the client, there is still two players, but on the host, it shows the client has disconnected, and I have this error message every time, any thoughts?
     
  7. SandeepSps

    SandeepSps

    Joined:
    May 26, 2017
    Posts:
    8
    Hi @vis2k ,
    I am struggling with WebGL build. I have it running if I don't use SSL settings, i.e. if I leave "client use wss" and "SSL enabled" as unchecked, but if I check these settings and add my certificate and json file, server starts but client can't connect to it. I am not sure what am I missing here.
    PFA the screenshot of NetworkManager and SimpleWebSockets
     

    Attached Files:

  8. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Please try our #help channel in discord or asking in the websockets transport channel.
    Never used that one myself :)
     
  9. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Mirror 2022.10 released on Asset Store (in a few minutes) & GitHub!
    2022-11-09 - 11-14-38@2x.png

    A decent month of improvements.
    Imagine what we could do if we were to work on Mirror full time :)
    https://github.com/sponsors/vis2k
     
  10. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
  11. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Pushed 2022.10 to the Asset Store again today.
    - Fixed Unity 2019/2020 support
    - Fixed WriteString missing EnsureCapacity
     
  12. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    CCU Test: trying the dirty callbacks PR for performance.
    NetworkIdentity.Serialize won't need to iterate all NetworkBehaviours to scan for dirty.
    Instead, NetworkBehaviours register themselves as dirty once they became dirty.

    + 5% reduction in bandwidth since merging Rpc buffers (7.08 MB/s -> 6.75 MB/s)
    + 15% faster world update (26 -> 22ms)

    (this uses NT V2 unreliable)

    Decent incremental improvement.
    Preparing for a larger dirty objects improvement.

    Note that this change is not on master yet.
     
    Last edited: Nov 12, 2022
  13. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    NetworkTransform V3 was merged as a new "NetworkTransformReliable" component.
    Feel free to test it in your projects.
    Keep existing (unreliable) NT if your game requires lowest movement latency.


     
  14. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    Hi,

    Was about to test mirror,
    but got few issues (downloaded zip, copied mirror and scripttemplates to project)
    Errors:
    "Vector3Long.cs(72,26): error CS1002: ; expected"
    "Assets\Mirror\Core\Tools\Vector3Long.cs(77,14): error CS1597: Semicolon after method or accessor block is not valid"

    using 2019.4.19f1
     
  15. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Fixed, please redownload current master from Github.
    Sorry about that, Unity 2019 does not run at all on my apple silicon mac so I can never try that one.
     
    whoft likes this.
  16. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    Thanks! it fixed that vector3, but new one popped up (i guess it didnt get to compile this far last time)
    Code (CSharp):
    1. Assets\Mirror\Core\NetworkServer.cs(1882,26): error CS0117: 'Time' does not contain a definition for 'timeAsDouble'
    seems that it appeared on 2020.2
    https://docs.unity3d.com/ScriptReference/Time-timeAsDouble.html

    upload_2022-11-17_19-59-36.png

    *replaced those with "NetworkTime.localTime"

    Then few more in:
    Assets\Mirror\Components\RemoteStatistics.cs(186,22): error CS0117: 'Time' does not contain a definition for 'timeAsDouble'
    upload_2022-11-17_19-50-27.png
    and few warnings:
    Assets\Mirror\Core\Tools\Vector3Long.cs(7,19): warning CS0660: 'Vector3Long' defines operator == or operator != but does not override Object.Equals(object o)

    *for testing replaced those with non double Time...

    then few more different errors:
    Assets\Mirror\Tests\Editor\Weaver\WeaverAssembler.cs(20,40): error CS0103: The name 'EditorHelper' does not exist in the current context
    Assets\Mirror\Tests\Editor\Weaver\WeaverTests.cs(50,13): error CS0103: The name 'CompilationFinishedHook' does not exist in the current context
    upload_2022-11-17_20-2-55.png
     
    Last edited: Nov 17, 2022
  17. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Thanks. Maybe best if you could upgrade to 2020 / 2021 LTS.
    We plan to stay on those for a long time. Wouldn't have upgraded if it wasn't for apple silicon.

    Gonna try to set up 2019 in a virtual machine this weekend.
     
  18. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    Adjusted those manually to non double Time's (and deleted Tests), so got my simple multiplayer test working.

    This project cannot upgrade at the moment, but later using newer version in next.
     
    mischa2k likes this.
  19. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Great news!
    We removed the last remaining client sided KCP allocation!
    The change is already live on GitHub and will be on the Asset Store in 1-2 weeks!
    2022-11-23 - KCP Client allocation free.png
     
    mgear likes this.
  20. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    whats the correct way to sync child transforms? (think player with VR hands for example)

    this one shows something, but adding "network transform child" says its deprecated:
    https://mirror-networking.gitbook.i...pickups-drops-and-child-objects#child-objects

    and cannot use that target field in main network transform,
    since root transform should be synced also (and need more than 1 target for hands, head)

    is there some builtin way or need to make separate script to send position/rotation data?
     
  21. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    You can use as many NetworkTransform components as you like.
    set one .target to itself.
    set another to children, etc.
     
    mgear likes this.
  22. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    Everything works great so far.

    One more question:
    I have player prefab (which is quite complex hierarchy, many components etc)

    When i join as a Client, it works fine.
    When another Client joins, it breaks things (since that player prefab has cameras, scripts etc).

    Is there some easy way of spawning separate prefab for non-local players?

    Currently i disable or destroy those extra components on Start, but it gets messy if anything changes..

    I checked this, and it says: can disable automatic spawning, so maybe somewhere there i can spawn just a simple sphere transfrom that has network transform..(for non local clients joining) ?
    https://mirror-networking.gitbook.io/docs/guides/gameobjects/player-gameobjects

    * or actually spawning separate remote player prefab might not work, since it doesnt have same network component as their matching local player?

    ** switched to simpler player prefab, works better.
     
    Last edited: Dec 2, 2022
  23. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    ".. is currently open in Prefab Edit Mode. Please open the actual scene before launching Mirror."

    Any way to make it automatically exit prefab edit mode, when user presses play? (so can enter playmode easily)


    ps. Docs: cannot copy paste from code snippets? (html uses complex spans?) upload_2022-12-2_14-31-44.png
     
    Last edited: Dec 2, 2022
  24. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Mirror Roadmap updated for 2023:
    https://trello.com/b/fgAE7Tud/mirror-networking

    Summary:

    1. Finish work-in-progress: KCP V2, LocalWorldState, etc.
    2. Minimize open bugs: gives us some breathing room.
    3. Advanced networking (prediction, etc.)

    Let's go :)
     
    akuno likes this.
  25. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    One more for the showcase :)
     
  26. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    If you are confused about what to use for hosting, check out our new Pragmatic Hosting Guide.
    It covers all the basic options: player hosted, nat punchthrough, relay, dedicated, cloud, orchestration.
    With recommends on what we use, and why :)
     
    MrBigly, B1X_gate and Willbkool_FPCS like this.
  27. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    377
    What happened to DOTSNET? I was just looking for it in the asset store after buying it a little while ago, only to find it deprecated. The whole reason I bought it was to support its continued development so I could use it down the road post ECS 1.0. Feels like a bit of a slap in the face to have it quietly disappear. :(
     
  28. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    See my post here: https://forum.unity.com/threads/dot...-creator-of-mirror.880777/page-7#post-8557625
     
  29. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    We are excited to announce the next Mirror LTS version!

    Mirror LTS gives you peace of mind to run your game in production.
    Without any breaking changes, ever!

    Mirror LTS
    is 50% off during launch while it's still a fresh branch!

    We are very happy with Mirror V70, it's the perfect version to support for two years.
    LTS is required by some game studios, as well as users who value peace of mind.
    After the 2 year lifecycle, V70 LTS will become MIT licensed as well.

    Stability is always our #1 priority: regular Mirror is still safe to use!

    If you have an ambitious project or want to support development, consider Mirror LTS!

    2022-12-21 - 13-53-46@2x.png
     
    mgear likes this.
  30. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    MERRY CHRISTMAS everyone!
    2022-12-24 - 17-03-43@2x.png

    Special thanks to all our GitHub sponsors for supporting Mirror.
    When we started, every other solution was either closed source or completely broken.
    Thousands of bug fixes later, and here we are - approaching 14.000 Discord users.

    Please remember: Mirror is free open source software!

    Mirror is not ours.
    It's yours, you all own it.
    You have the freedom to modify it.
    You can help improve it.
    Even ten years from now, you can still fix it.
    And if we stop doing great work, you must fork it.

    Open Source
    brings value to the people.
    And no one can ever take it away.
    This is what we believe in.
    And thanks to this beautiful community, we made it this far!

    Love you all, cheers. :)
     
    Last edited: Jan 4, 2023
    MrBigly and joeconstable97 like this.
  31. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    First 2023 Update!
    We are working towards fixing all open bugs.
    This update brings ~20 bug fixes in Mirror/KCP.
    All of them were ported to Mirror LTS, which is 50% off for 3 more days!
    Enjoy!

    2023-01-01 - 12-21-55@2x.png
     
  32. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
  33. joeconstable97

    joeconstable97

    Joined:
    Jul 30, 2013
    Posts:
    50
    Hello,
    For my game, I'm using a "host" (client and server running together in one instance)

    Is it possible to decouple to client's framerate from the server's tickrate?
    i.e. have the client run unclamped at say 200fps while having the server only tick at 30?

    I know there is the tickrate property in the NetworkManager but that just locks the framerate of the instance.

    Cheers
     
  34. patrickk2

    patrickk2

    Joined:
    Dec 8, 2019
    Posts:
    92
    Hello everyone!

    I have a question regarding NetworkTransforms. The client is build for WebGL and only uses 2D sprites. The movement of other players is very noticably shivering while they are moving, and I was hoping you could point me to some settings that might need adjusting or common pitfalls that I might have missed.

    As of now the sync direction is client to server, I'm currently in the process of reworking that to server authority, but if there are any other points to look out for, I would really appreciate any input on this issue.

    Thanks in advance and best regards,
    Patrick
     
  35. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Does it happen with our built in tanks demo as well?
     
  36. patrickk2

    patrickk2

    Joined:
    Dec 8, 2019
    Posts:
    92
    Hello @vis2k!

    Thanks for the response! I will try that as soon as I can.

    Best regards,
    Patrick
     
  37. patrickk2

    patrickk2

    Joined:
    Dec 8, 2019
    Posts:
    92
    Hello @vis2k!

    I can't reproduce the problem in the tanks demo. I will investigate the differences further and come back to this thread, when more questions arise. Thanks for your response!

    Best regards,
    Patrick
     
    mischa2k likes this.
  38. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Congrats everyone, it's been ~9 years of Mirror / UNET.

    Mirror is the longest running 'client & server in one' netcode for Unity, and always will be :)

    One hell of a ride, with the best yet to come in 2023.





    2017-08-13_stresstest.png
     
    hopeful, akuno, Flowan_ and 1 other person like this.
  39. AgaDeoN

    AgaDeoN

    Joined:
    May 19, 2020
    Posts:
    9
    Hello. I've found that I need new network solution for my game and I'm considering mirror right now, but it seems a little confusing for me.

    Let's say I have a turn-based game with two teams. Players of the same team should know all the information about allies and ONLY SOME information about enemies. For example players of one team should know positions of allies and EXACT amount of their HP. At the same time, they should know enemies positions and only the percentage of their HP (not the exact numbers).

    I can't understand how can I achieve this using "high-level" API, i.e. syncvars, commands and rpc. Is it possible or I should look towards "low-level" API, i.e. "net messages"?

    All the "tutorials" I've found cover only the most basic things, like "let's create two cubes which will move on every connected client. Scope is a complicated topic so we won't consider it..."

    Сould you tell me which direction to look in, or is it just better to look for alternatives for such kind of game?
     
  40. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Answered in discord :)
     
  41. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Mirror V73 is on the Asset Store!
    Another 26+ bug fixes this month. With patience, we will get to 0 open bugs!
    As usual, all fixes were applied to both Mirror & Mirror LTS.

    Special thanks to all the people who purchased Mirror LTS!
    The income will go directly towards Mirror development, and even more bug fixes :).

    If you enjoy stability & peace of mind, give Mirror a try!

     
  42. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Weekend Showcase: SWARM VR - the next VR hit for the Meta Quest, made with Mirror!
    2023-03-03 - 09-51-06@2x.png
     
  43. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Unifikation, r137, Lion_C and 2 others like this.
  44. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
  45. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Unifikation likes this.
  46. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
  47. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Update on our stance on Free & Open Source development.
    We hope that this makes it more clear what our incentives are for Mirror.

    Please join our Discord community if you haven't already!

    2023-06-26 - README incentives.png
     
  48. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Great news for First Person Shooters & fast paced Mirror games!

    Lag Compensation V1 algorithm is live, based on Valve's excellent article.
    Pull Request: https://github.com/MirrorNetworking/Mirror/pull/3534
    Documentation: https://mirror-networking.gitbook.io/docs/manual/general/lag-compensation


    We provide a minimal, easy to understand demo in Examples/Lag Compensation:


    The algorithm is standalone C#, independent of Unity and Mirror:


    As usual, with full test coverage around all the edge cases:


    --------------
    Our goal was to ship V1 of the algorithm quickly in order to make this available for all the Mirror first person shooter games today.

    In the future, we will provide a FPS demo to showcase this better.
    We will keep improving the algorithm over time, based on user feedback.

    For now, feel free to use the Lag Compensation algorithm and let us know how you like it!
     
  49. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    HistoryCollider for Lag Compensation & Client Side Prediction.



    HistoryCollider is a 4 dimensional collider (xyz+time), which can be used as an early check to decide which objects to rollback for lag compensation & prediction.

    => After lots of optimizations with imer and FakeByte , we got it down from 183ms to 35ms for our benchmark. This is in the Editor, so an IL2CPP build will give us another 2-4x.

    => Heavy test coverage to ensure stability. This is part one of client side prediction & reconciliation.

    Useful for Lag Compensation too, so we worked on this first!
    Pull Request coming up later this week !
     
    jesusluvsyooh and akuno like this.
  50. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Check it out guys, Mirror games getting mentioned on Joe Rogan podcast:
     
    Last edited: Jul 31, 2023
    akuno likes this.