Search Unity

Unity Multiplayer Mirror - Open Source Networking for Unity

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

  1. JamesFrowenDev

    JamesFrowenDev

    Joined:
    Oct 10, 2015
    Posts:
    3
    Reading through this, https://tools.ietf.org/html/rfc6455, there are 2 random parts. The random key added to the header when doing the handshake, and the random mask the client uses to encode each of their messages.

    It is kind of unclear about if the header should be secure random because it is only sent once at the start:

    It does say that the mask should be secure random so that it cannot be predicted:

    I think the old transport (NinjaWebSocketsTransport) uses
    System.Random
    for the header and mask. However the new transport (SimpleWebTransport) uses
    RNGCryptoServiceProvider
    for the mask, and I will probably change the header to use it as well just to be safe.
     
    vis2k likes this.
  2. tungqlvip

    tungqlvip

    Joined:
    May 7, 2018
    Posts:
    5
    marginally a little bit.
    in telepathy I only see 3 default event types: connect, disconnect and data. how can I add a new type of event to handle while client.send doesn't pass any parameter which is the event type. Default client. send typeevent will be data ??
     
  3. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,005
    KCP transport [https://github.com/vis2k/kcp2k] released!

    Why KCP:
    https://github.com/skywind3000/kcp/blob/master/README.en.md
    + 100% C#.
    + Works on all platforms except WebGL.
    + Heavy test coverage (83.5%).
    + Extremely fast.
    + Extremely simple.
    + Nearly allocation free*. "

    KCP is a fast and reliable protocol that can achieve the transmission effect of a reduction of the average latency by 30% to 40% and reduction of the maximum delay by a factor of three, at the cost of 10% to 20% more bandwidth wasted than TCP. It is implemented by using the pure algorithm, and is not responsible for the sending and receiving of the underlying protocol (such as UDP), requiring the users to define their own transmission mode for the underlying data packet, and provide it to KCP in the way of callback. Even the clock needs to be passed in from the outside, without any internal system calls."


    We are very excited about KCP and highly recommend trying it in your project.

    => Previously we had pure C# transports that were slow
    =>
    And native C transports that were fast, but hard to maintain.

    KCP brings us the best of both worlds: it's as fast as our native C transports, while still being easy to maintain because it's 100% pure C#!

    KCP is the new default Transport for Mirror, already live on Github and coming to Asset Store in the next few days!

    This is a significant leap forward for 2020-11-03_16-18-36.png and our games.
    Enjoy!

     
  4. PartyBoat

    PartyBoat

    Joined:
    Oct 21, 2012
    Posts:
    94
    The new version of Mirror (26.2.2) now seemingly has a dependency on Unity's Performance testing API package. I really would rather not have any extra dependencies in my project (especially a preview package). I removed the dependency and everything compiled and seems to be working fine. Was this just a mistake with the release submitted to the asset store?
     
  5. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,005
    I probably checked 'include dependencies' when uploading it to the Asset Store.
    But you don't need any dependencies, everything is in the folder :)
     
  6. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,005
  7. mholmes

    mholmes

    Joined:
    Dec 8, 2012
    Posts:
    397
    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.
     
  8. 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.
  9. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,005
    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
  10. 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.
  11. 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
     
  12. 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
  13. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,005
    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.
     
  14. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,005
  15. 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.
     
  16. patrickk2

    patrickk2

    Joined:
    Dec 8, 2019
    Posts:
    63
    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
     
  17. no00ob

    no00ob

    Joined:
    Dec 13, 2017
    Posts:
    61
    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
  18. Ziron999

    Ziron999

    Joined:
    Jan 22, 2014
    Posts:
    265
    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.
  19. 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.
  20. Ziron999

    Ziron999

    Joined:
    Jan 22, 2014
    Posts:
    265
    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?
     
  21. 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.
     
  22. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,005
    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...
     
  23. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,005
    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.
  24. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,005
    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.
  25. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    10,502
    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.
     
  26. gamevanilla

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    957
    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.
  27. FakeByte

    FakeByte

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

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,005
    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.
     
  29. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    804
    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.
  30. neginfinity

    neginfinity

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

    gamevanilla

    Joined:
    Dec 28, 2015
    Posts:
    957
    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.
     
  32. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,005
    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
     
    MassimoFrancesco likes this.
  33. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    804
    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 :)
     
  34. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    804
  35. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,005
    Ruchir likes this.
  36. SteveDClarke

    SteveDClarke

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

    Barritico

    Joined:
    Jun 9, 2017
    Posts:
    348
  38. SteveDClarke

    SteveDClarke

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

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,005
    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.
  40. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,005
    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! :)
     
  41. 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 :)
     
  42. mholmes

    mholmes

    Joined:
    Dec 8, 2012
    Posts:
    397

    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. .
     
  43. Ruchir

    Ruchir

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

    mholmes

    Joined:
    Dec 8, 2012
    Posts:
    397
    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.
     
  45. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,005
  46. Tom-Kazansky

    Tom-Kazansky

    Joined:
    Mar 9, 2015
    Posts:
    14
    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.
     
  47. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,005
    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.
  48. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,005
  49. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    804
    vis2k likes this.
  50. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,217
    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
unityunity