Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Unity Multiplayer Mirror - Open Source Networking for Unity

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

  1. mholmes

    mholmes

    Joined:
    Dec 8, 2012
    Posts:
    407
    My frustration level with this is through the roof. So far I have not been able to find tuts that's are complete. When I loaded Mirror into Unity from Asset store the examples are missing scripts. The discord offers links to videos but you must pay to get the full access. I'm brand new to Multiplayer networking so its very difficult when you make it so hard to find information or setup the tool out of the box. I've been coding for several years but very frustrating when you try to learn something new and very little support. the best free videos i have found so far on mirror are
    but this is very lacking and I have not been able to get this working. It would be helpful if when you import things from asset store they don't break or the third party makes it easy to find free resources to support the product.
     
  2. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    261
    Just don't use Mirror. Unity sums it up pretty succinctly in the document attached to this blog post, though they're more kind in the blog post itself: https://blogs.unity3d.com/2020/09/08/choosing-the-right-netcode-for-your-game/

    Use MLAPI. Not ANY harder than this stuff, especially if you're starting from scratch. Unity recently hired that developer and announced it's their supported networking solution for MonoBehaviour projects going forward. I had great luck with that community a couple years ago when I was working with MLAPI for a bit, but game networking is a mind-melter no matter what. Good luck!
     
    uberwiggett and mholmes like this.
  3. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,219
    Those videos are not from the Mirror team, they are from a community member.
    Asset Store project works perfectly fine for everyone if you use 2018.4 LTS or 2019.4 LTS.

    Let us know how we can help.

    The linked study is based on false facts:
    • Mirror got heavily downrated because we supposedly use Linq. A simply CTRL+F search for 'Linq' proves that we don't use Linq anywhere in hot path.
    • Mirror got downrated because we supposedly have heavy allocations. While the old Telepathy transport still has them, Mirror itself and all of the newer transports like kcp/libuv/apathy are allocation free in hot path. This was actually very important for our biggest VR project Population: ONE. Runtime allocations / GC pauses cause motion sickness in VR, so that's not an option.
    • The study classifies Mirror for <32 CCU. Even UNET back in the day was able to do 70 CCU. We moved way past that years ago. 500 CCU should be doable, and we are aiming for another 500-1000 CCU community test some time in the next few months.
    As reminder, the scientific method requires actual measurement and tests. This is very hard to do. Unity chose to ask for people's opinions instead :)

    We wish best of luck to the MLAPI community. This question comes up a lot and the answer is always the same: we didn't make Mirror to compete with anyone. Paul and I made it because we had no other choice. We would rather focus on our games than worry about networking.
     
    Last edited: Dec 30, 2020
  4. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,557
    I think it's pretty much established fact that Unity dropped the ball on Networking; their code never was complete, never really worked, and the documentation -- what tattered parts of it that existed -- was really, really bad, incomplete, and buggy.

    One of our games was based on UNet, and we replaced that with Mirror / Steam P2P as Transport layer, and it has resolved a lot of Issues. I'm not affiliated with the Mirror team, and have no stake in their success -- they have done a tremendous work, vis2k in particular (thanks again!!!)

    Unity networking currently is in a sorry state and I have seen very little encouraging new besides them pulling a 'cloud imperium' -- a roadmap for a roadmap.
     
    MassimoFrancesco, xVergilx and vis2k like this.
  5. sravan-asura

    sravan-asura

    Joined:
    Jan 22, 2016
    Posts:
    1
    Hi ,
    I am facing a problem with mirror that is i want to make communication (chat system) between apk (which is in quest2)and pc but its not getting connect so can any one please help me thanks in advance
     
  6. tim44

    tim44

    Joined:
    May 15, 2019
    Posts:
    58
    Edit. Checked on discord and this was a bug in current version. Github version worked

    When I run on Android I get this, not sure how to handle this exception or if it can be ignored:
    It floods the adb debug window though.

    01-09 13:15:32.114 10536 10554 E Unity : NullReferenceException: Object reference not set to an instance of an object
    01-09 13:15:32.114 10536 10554 E Unity : at Mirror.NetworkWriter.WriteBlittable[T] (T value) [0x00051] in \Assets\Mirror\Runtime\NetworkWriter.cs:206
    01-09 13:15:32.114 10536 10554 E Unity : at Mirror.NetworkWriterExtensions.WriteDouble (Mirror.NetworkWriter writer, System.Double value) [0x00000] in \Assets\Mirror\Runtime\NetworkWriter.cs:282
    01-09 13:15:32.114 10536 10554 E Unity : at Mirror.GeneratedNetworkCode._Write_Mirror.NetworkPingMessage (Mirror.NetworkWriter writer, Mirror.NetworkPingMessage value) <0xc8298e30 + 0x00047> in <83d0ec5c224a4aa99079f8a204de0f7c>:0
    01-09 13:15:32.114 10536 10554 E Unity : at (wrapper delegate-invoke) System.Action`2[Mirror.NetworkWriter,Mirror.NetworkPingMessage].invoke_void_T1_T2(Mirror.NetworkWriter,Mirror.NetworkPingMessage)
    01-09 13:15:32.114 10536 10554 E Unity : at Mirror.NetworkWriter.Write[T] (T value) [0x00033] in \Assets\Mirror\Runtime\NetworkWriter.cs:249
     
    Last edited: Jan 9, 2021
  7. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,219
    Yep, unfortunately it works on all platforms except android.
    Seems to be a Unity bug. We'll send a bug report, but they never get fixed anyway.
     
  8. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,219
  9. ZachHelm

    ZachHelm

    Joined:
    Jul 9, 2013
    Posts:
    4
    That's awesome! Hopefully Steam will step up their game with cross-platform services outside of their own platform as well. The more the merrier.

    I came here to report that I didn't have KCP with package version 30.2.2, but the problem turned out to be at my end. I could see KCP in the Package Contents on the asset store page, but not after importing "version 30.2.2" into my project. The package manager kept telling me I'm up-to-date. I go to the roaming folder, and sure enough, it's a version from last April. :eek: The moral of the story is to just delete that folder at %AppData%/Unity/Asset Store-5.x/ every once in awhile, or grab it from GitHub.
     
  10. patrickk2

    patrickk2

    Joined:
    Dec 8, 2019
    Posts:
    71
    Hello everybody!

    I have a question about scene management. In the NetworkManager of my testproject, I specified the main scene and a simple offline scene. For the connections, I use the Mirror NetworkManagerHUD component.

    When I click "Client" on my client build, the "game" starts as expected and spawns a little triangle which moves around. When I either stop the server, or click on "Stop client", the game changes to the offline scene as expected.

    But when I click on the "Client" button again (after restarting the server if necessary), the game does not change back to the online scene. The NetworkManagerHUD will display the "Client ready" button which spawns the player prefab, but I am still in the offline scene.

    Does anybody have any tipps, what might cause this, or what I might be doing wrong here?

    Thanks in advance for any input on this issue and best regards,
    Patrick
     
  11. no00ob

    no00ob

    Joined:
    Dec 13, 2017
    Posts:
    62
    I've been using Mirror for my game for a while now and it's been great! However, today after a build Mirror started spewing out this error whenever I tried to host a game.
    Code (CSharp):
    1. NetworkManager has a NetworkIdentity component. This will cause the NetworkManager object to be disabled, so it is not recommended.
    2. UnityEngine.Debug:LogError(Object)
    3. Mirror.NetworkScenePostProcess:OnPostProcessScene() (at Assets/Asset Store/Mirror/Editor/NetworkScenePostProcess.cs:37)
    4. UnityEditor.Build.BuildPipelineInterfaces:OnSceneProcess(Scene, BuildReport)
    I haven't changed anything and made sure that the NetworkManager that I use doesn't have a network identity anywhere near the object where it is attached to. I seemingly can't get rid of this error no matter what I do...

    Edit: I'm just a bit slow lol I hadn't set the correct scene as the menu one in the inspector... Forgot to switch it as I made a new one.
     
    Last edited: Feb 2, 2021
  12. Ziron999

    Ziron999

    Joined:
    Jan 22, 2014
    Posts:
    270
    The obvious question i have in this insane amount of pages of text that is probably answered is; Does this actually use UNET? are you limited on CCU? how do you host a master server with something like this? Is it even possible?
    Basically: Is it "ACTUALLY" free if you were to release a game? can you host it yourself?
     
    mgear likes this.
  13. FakeByte

    FakeByte

    Joined:
    Dec 8, 2015
    Posts:
    147
    Mirror is based on UNET, but is completly reworked.
    There is no limit on CCU. It's completly free and open source.
    You can let players host games or you can host your own games.

    What kind of master server do you need? If its a list server that shares a list of all servers to your players then there is the mirror list server which cost 20$ per month and is hosted for you or you use the node list server which is free and open source and you host yourself. https://github.com/SoftwareGuy/NodeListServer
     
    akuno, Zullar and vis2k like this.
  14. Ziron999

    Ziron999

    Joined:
    Jan 22, 2014
    Posts:
    270
    Well there is certain player information that would be on a master server while other information is just a session. The players, level, money, stats, whatever it may be should be on the master server on an SQL database (preferably) unless you know of something faster to process large amounts of data quickly. That would be helpful to know as well.
    The complicated thing to also control on a master server is hack detections. So if you host a game you can hack it 100% if you go down that road. That is the problem with player hosting setups. The host can completely destroy the game without any repercussion. This is the most complicated thing to fix. Would you just rely on Steam's VAT? is it possible to integrate that with this somehow?
     
  15. FakeByte

    FakeByte

    Joined:
    Dec 8, 2015
    Posts:
    147
    So you only host dedicated servers?
    Or will you allow players to host servers too?

    I usually prefer a NoSQL database for game data, if you host all servers then you can let the game servers directly connect to the database, otherwise if players can host servers you either need a middle man server (master server) or you use unity web requests to request database info from a webserver running something like php.

    You can integrate Steam VAC using Steamworks.Net, but this only works on servers that you host and you have to first upload the cheat/hack to valve before it can detect it, which means you will have to actively look for cheats/hacks all the time if you want to use Steam VAC.

    If you really care about cheaters make your game server authoritive and validate every player input correctly, then its almost impossible to cheat and you wont need any other special tools.
     
  16. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,219
    Batching now live on Github!

    Mirror now batches multiple messages into ideal sized (usually MTU) packets before sending them out.

    Batching can be enabled in the NetworkManager! It allows for enormous CCU improvements.
    -> Benchmark & KCP: 2,000 => 20,000 monsters
    -> @JesusLuvsYooh 150 CCU tests: ~50% lower CPU usage; reduced bandwidth

    Use
    Batching if your game needs to scale.
    Don't use Batching for extremely fast paced games as it increases latency slightly (for now).

    Batching & Transport Month
    combined will greatly improve the next 500-1000 CCU test. Transport month about to be finished...
     
  17. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,219
    Telepathy V1.6 live on Mirror & Telepathy Github, coming to all assets soon!

    => lots of bug fixes and improvements.
    => fixed data races
    => allocation free!

    Performance CCU tested & confirmed by JesusLuvsYooh.
     
    partridge and no00ob like this.
  18. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,219
    Global InterestManagement component coming to Mirror.
    This allows us to add Spatial Hashing, also known as GridChecker from uMMORPG :)

    Spatial hashing gave a 30x improvement in interest management speed when we measured it a few years ago.

    2021-02-12_16 - gridchecker.png
     
    Yavvn likes this.
  19. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    11,985
    I have a question.

    Mirror allows player to send out Commands, however it is unclear if the commands are received in the same order as they're sent.

    I.e. whether the communication is similar to TCP (meaning packets arrive in order, and if lost, they are resent), or if it is closer to UDP (meaning data is sent out of order).

    This is kinda important to me, because I'm trying to make player stream data to other people.
     
  20. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    The default networking transport used by Mirror is Telepathy and is TCP, but there are alternative transports available as well. You can find a complete list here.
     
    neginfinity likes this.
  21. FakeByte

    FakeByte

    Joined:
    Dec 8, 2015
    Posts:
    147
    By default they use a reliable ordered channel
     
    vis2k and neginfinity like this.
  22. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,219
    Depends on the transport.
    Telepathy and KCP Reliable channel is ordered too.
    Mirror actually expects the reliable channel to be ordered for the spawn messages at least.
    Maybe we should make this more obvious.

    The unreliable channel has no ordered guarantees by the way.
     
  23. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    885
    Can anyone tell me if there's a good tutorial series on how to get started with mirror and some series on advanced features like matchmaking, lobby creation, hosting servers, and other features using mirror?
     
    MassimoFrancesco likes this.
  24. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    11,985
    Mirror website has documentation and mirror unity package comes with examples that cover at least some of those topics.
     
  25. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    970
    Not exactly a tutorial, but our Dedicated Server Kit asset can be helpful to learn how to implement several of these concepts in the context of Mirror game server instances.
     
  26. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,219
    Mirror Documentation has moved to Gitbook!
    - Our old documentation was super hard to work with and took 20 mins to release.
    + Gitbook is easy to use, immediate and fun and beautiful.
    2021-02-26 - gitbook.png

    feelsgood.jpg
     
    raul3d and MassimoFrancesco like this.
  27. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    885
    Could you please add an example fps game that shows how to handle bullets and animation and other small things which are hard to find in individual tutorials/examples?

    Would really help a lot :)
     
  28. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    885
  29. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,219
    raul3d and Ruchir like this.
  30. SteveDClarke

    SteveDClarke

    Joined:
    Aug 15, 2017
    Posts:
    6
    Is the mirror-networking.com site down? I can't access the API documentation.
     
  31. Barritico

    Barritico

    Joined:
    Jun 9, 2017
    Posts:
    362
  32. SteveDClarke

    SteveDClarke

    Joined:
    Aug 15, 2017
    Posts:
    6
  33. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,219
    Should be back up in a few hours. It was under DDOS attack according to the hoster.
    Possibly because of a wrong 301 redirect when moving the documentation :)
     
    Ruchir likes this.
  34. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,219
    Optimized Update Order
    Mirror previously used LateUpdate to process incoming and outgoing messages.
    This introduced possible data races & unnecessary latency.

    We've added custom NetworkEarlyUpdate/NetworkLateUpdate functions to Unity to allow for a proper network update loop:
    Code (CSharp):
    1. process_incoming(); // EarlyUpdate()
    2. update_world(); // Fixed/Late/Update()
    3. process_outgoing(); // After LateUpdate()
    In other words, incoming messages are now applied before we update anything.
    Outgoing messages are now sent after we updated everything.

    This reduces localhost RTT from 30ms to 14 ms (see bottom right):
    2021-03-02 - early and late update - before and after.png

    Updating:

    Updating to the latest Mirror on Github (and using kcp) will give you the latency improvements for free.
    There is nothing you need to change in your projects!
    This change is 100% Mirror internal.
    Usage remains exactly the same.

    Other Transports
    :
    Transports need to utilize the new Client/Server Late/EarlyUpdate() functions to see the latency improvement.
    Our built in #kcp Transport already does, others will follow over time!

    This is a major leap forward.
    Enjoy! :)
     
  35. dgkanatsios

    dgkanatsios

    Joined:
    Jun 27, 2014
    Posts:
    1
    I'm working on migrating this sample to work with the latest version of Mirror. I've replaced the library files and replaced inheritance from MessageBase to NetworkMessage, however I'm seeing some compilation errors, specifically on the "OnReceiveAuthenticate" method
    1. NetworkMessage used to have a property .conn. It seems that it's now gone. Any hints on what I should replace it with?
    2. NetworkMessage used to have a method .ReadMessage<T>. What should I replace it with?

    Anything else that we should pay attention while migrating? This is a pretty bare bones sample, open to any feedback. FWIW, if anyone wants to contribute a PR, that would be greatly appreciated as well!

    Thanks, appreciate your time :)
     
  36. mholmes

    mholmes

    Joined:
    Dec 8, 2012
    Posts:
    407

    Ohh Tell me more about ML API. My experience with Mirror got worse. I'll never use this solution. 400 bucks later learned my lesson. I'll look into ML API I heard about it before but did not know its a multiplayer solution. Have you used Hamchi with it or Client + Host? I'm just trying to build a basic "Co Op" multi player game option for already finished game. .
     
  37. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    885
    Could you please elaborate as I am still looking for one to base my project on.
     
  38. mholmes

    mholmes

    Joined:
    Dec 8, 2012
    Posts:
    407
    I'm doing a simple co op so someone suggested I use parsec. It's a remote desktop. So you would setup like a controller 1 and controller 2 setup. But photon I heard as well is really good. Talking to some guys that build photon professional for unity drvs such as my self and work on collab agreement. The suggested ML API sounds good too. I have a .net api I use currently but nothing for gaming. It's more for accounts etc. So I'm excited to try ml api. Don't use mirror. That's what I recomend. I hired a guy to help me get mirror working. He was one of there devs and it still does not work. Had a friend review it and he said don't use this. I read the code as well and had same feeling. It's not a good solution. What is the price of free.
     
  39. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,219
  40. Tom-Kazansky

    Tom-Kazansky

    Joined:
    Mar 9, 2015
    Posts:
    39
    Hello,
    I'm a beginner to multiplayer game,
    I want to make a 2D mobile (Android) game with co-op mode (up to 4 players in one game session)

    I try PUN2 solution but that seems to implement "Listen server" but I want "Dedicated game server".
    (maybe I have not digged deep enough)

    does Mirror support "Dedicated game server"?

    briefly about the game flow that I expecting:

    - player open the game
    - connect to a lobby
    - retrieve list of "rooms" in this lobby
    - player can connect to an existing room or create a new room
    - after all players are ready, the game start
    - during gameplay: if a player disconnect, that player should be able to reconnect and continue playing
    - after said game session finish, players return to the lobby

    it would be great if someone can give me some pointers for this, maybe some specific classes that I should look into?

    thank you for reading,
    Tom.
     
  41. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,219
    Mirror is meant for dedicated servers by default yes.
    Lobby is usually an extra service.
    Check out the epic transport for Mirror, I think it has lobby now (the one from epic online services, which is free).
     
    Tom-Kazansky likes this.
  42. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,219
  43. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    885
    vis2k likes this.
  44. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,227
    Is there a trick to getting mirror working on iOS. My project works perfectly on PC but on iOS the client just times out. If I try the server on iOS I can start it and connect but it never recieves any commands.

    edit: ignore me I solved it. I was using port 80 for testing. When I opened another port and tried that instead everything worked.
     
    Last edited: Mar 23, 2021
  45. tenukii

    tenukii

    Joined:
    Mar 31, 2014
    Posts:
    12
    vis2k likes this.
  46. shawnblais

    shawnblais

    Joined:
    Oct 11, 2012
    Posts:
    323
    Sorry if this is answered in the docs, I couldn't find anything specifically talking about size limits, or where to store large amounts shared data.

    We're considering using Mirror for a Valheim-style game, it would be procedurally generated, and have a very large list of world modifications and items that all players would need to share, the owner of the world would provide the seed, and the list of world modifications, anyone else can write back to that list while the game is running.

    Is this doable with mirror? Would we just use a hash-table to share all the info amongst players?
     
  47. dario17231

    dario17231

    Joined:
    Nov 21, 2020
    Posts:
    1
    Did you find a solution for this error? Which transport are you using?
     
  48. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,219
    Most transports have a configurable max message size.
    Default kcp transport max message size is around 140 KB.
    Other transports like Telepathy can have up to 2GB (although that might not be a good idea).
     
  49. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,219
    Yes, this was an android mono bug.
    You need to upgrade to latest Mirror on github :)
     
  50. funkyjive

    funkyjive

    Joined:
    Jan 11, 2013
    Posts:
    2
    I'm wondering if I'm missing something obvious here so let me make a few statements and see what I am doing wrong with my setup.

    Context: Networked game where the players are relatively slow moving balloon objects that can bump into each other as physics entities. Because the movements are relatively slow I am ok with all physics taking place on the server and clients have smooth positions and rotations albeit slightly delayed from the physics happening on the server. The gameplay is slow enough I think that would work but the key item is that the movement needs to be smooth since this is VR and if the rig jitters motion sickness happens. I'm willing to trade latency and client side accuracy for smoothness.

    So the player object has a rigidbody and some colliders.

    Here's what I've tried and observed:

    Config 1) Simple network transform on the prefab, sync interval set to 1. Client has occasional "hiccups" where rotation and position isn't exactly smooth. Almost tolerable. I'm guessing the rigidbody on the client still being active is fighting with the network transform?

    Config 2) Same as config 1 but sync interval set to 0. Much choppier than config 1. I assume sync interval 0 means only send transform updates when the sensitivity threshold value is hit?

    Config 3) Same as config 1 and 2 but sync interval set to 0.01. Much choppier than config 1. Still seeing hiccups and jitter.

    Config 4) Network Lerp rigidbody. Rotations don't seem to be happening from server -> client. Position and velocity looks smooth but no rotations.




    Question 1) Does network transform do any interpolation? If so then I must be seeing the effects of the rigidbody still being active on the client causing stuttering.

    Question 2) Is there a reason lerp rigidbody does position and velocity but not angular velocity or rotation? I don't think this is the right solution for my use case of wanting the physics to only run on the server but it was something I tried anyways.

    Question 3) One config I did not try is the simple network transform but having some script client-side disable its rigidbody. As I type this out it seems obvious that leaving the rigidbody component enabled on a client seems like it would only screw up the client side movement. I'll be trying that next. It looks like there is no "enable" for rigidbodies like some other components. There must be some other way around that.
     
unityunity