Search Unity

Unity Multiplayer Mirror - Networking for Unity (UNET Replacement)

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

  1. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,243
    Check out the examples folder that comes with Mirror.
    MrGadget created a lobby already.

    Those aren't needed anymore :)
     
  2. JLJac

    JLJac

    Joined:
    Feb 18, 2014
    Posts:
    30
    Thanks for your answer. In the examples I can find several LAN examples, as well as one List Server example (the tank game). What I want is just:

    - A text label that shows my IP.
    - A host button and a join button.
    - A text field where I can enter my friend's IP and press join.

    So, skipping the entire "matchmaking" step - I'll get to that later, but first I just want two computers to talk to each other in the simplest way possible, ie by manually entering the IP. Is this possible? I'm very confused that I can't find examples of this anywhere in online tutorials, as I feel it would be the very natural first step (rather than building some big lobby infrastructure with dedicated list servers etc) and I am wondering if I am missing something obvious.
     
  3. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,243
    News: we have been doing MAJOR performance improvements to Mirror. The screenshot shows the uMMORPG stress test from last year, and from today. Notice how in the third table (which was today), raw Mirror+Telepathy is now almost as fast as the booster, and around 10x faster than last year (when considering latency at 400+ CCU).

    Just to be clear, this is the current Mirror master. Nothing experimental, this is available to everyone right now!

     
    hopeful likes this.
  4. antey3064

    antey3064

    Joined:
    Mar 21, 2016
    Posts:
    15
    Please do the stress test of the USurvival asset. Since dynamic MMOFPS and MMORPG are completely different things.
     
  5. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,140
    Still nonsense numbers, what are the tickrates?

    What indicates that the new builds are faster? What are the updates per second? Only difference I see is higher latency?

    Or are you telling me the ms is the ticktime??
     
  6. blacksun666

    blacksun666

    Joined:
    Dec 17, 2015
    Posts:
    158
    I assumed the tick rate was 50Hz? Can anyone confirm this? Also what the network latency is this was tested across i.e. lan speed network,etc?
     
  7. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,140
    Oh right.. now it makes even less sense. I didnt notice the 50Hz.

    Assuming both run 50 ticks per second, and use the same amount of CPU. That tells me no speed improvement. (Because it uses the same amount of CPU for the same amount of work). Instead a speed degredation. The old version handled 450 at 96% and the new one handles 420 at 97%. So it's worse results. ASSUMING that they both run exactly 50 ticks per second. Which probably isnt the case since you are maxing your CPU. You probably set TARGETframeRate to 50 and called it the day.

    Instead, dont lock the tickrate. Let both run, and see how many ticks per second each build can pump. That way you get meaningful results. If the new build runs twice as many iterations per second, it's twice as fast. Simple. But I assume you probably have tons of variables in your benchmarks, such as graphics and stuff.
     
    Last edited: Jul 11, 2019
  8. dorgenark98

    dorgenark98

    Joined:
    Mar 15, 2017
    Posts:
    8
    Hi, I was using your network solution on my project in Unity Version 2017 and it worked so well, after few months of development I decided to recreate(from scratch) my project in Unity 2018.4 but I got a problem now, the objects already in scene with network identity only spawn in Server and not in Client, what am I doing wrong?

    Edit: I tried with build/build and build/editor also.
     
    Last edited: Jul 11, 2019
  9. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,243
    Did you try to delete your library folder and then reimport it?
    Do you get any error messages?
    Are all the prefabs added to the NetworkManager's spawnable prefabs list?
     
  10. Genay78

    Genay78

    Joined:
    Jul 5, 2019
    Posts:
    21
    Hi!

    I'm a indie and I'm making a multiplayer game (4 players), in a persistant environment.
    I'm looking for tools to create a p2p authoritative architecture as I'm not into network programing.

    Am I knocking at the right door? Would Mirror be suited for that?

    Thank you for your answer :) !
     
  11. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,243
    Try it :)
     
  12. Genay78

    Genay78

    Joined:
    Jul 5, 2019
    Posts:
    21
    That means it should handle p2p pretty well haha !

    I'll try it for sure, and thank you for your work here. Very much
     
  13. F-R-O-S-T-Y

    F-R-O-S-T-Y

    Joined:
    Mar 22, 2013
    Posts:
    232
    Doesn't ms dictate the speed? Could you elaborate on this further?

    Thanks!
     
  14. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,243
    The benchmark results are mostly about latency.
    If the server chokes, the latency goes up. If the latency stays low, the server can handle the players well.
     
  15. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,140
    Ms is milliseconds. It's not documented what this is, I'm assuming latency. Latency is not neccecarly the same as tickspeed. Because they both run at 50hz. So I have no clue how the F*** one would produce such garbage results as 1k ms. I'm assuming by like processing one packet per tick.
    So they are not running at 50hz like documented? Why don't you release one showing how many ticks per second each can produce? That way you can see a straight difference.
     
  16. blacksun666

    blacksun666

    Joined:
    Dec 17, 2015
    Posts:
    158
    @vis2k I'm still not sure what the benchmarks are showing. Do they show the server sending out updates every 20ms (50Hz) but those updates take the stated latency to affect the clients (due to server,network and client delays)? Given the CPU usage on the main thread how sure are you that the updates are still maintained at 20ms intervals?
    Basically trying to find out if the clients have a steady 20ms update but the updates are delayed by the stated latency based on the number of CCU or if the client sees their update rates drop to the stated latencies?
     
  17. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,243
    Yes, tick rate drops when more players connect, that is why the latency increases.
     
  18. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    684
    The missing explanation:

    These tests show 3 transports working with uMMORPG, one of @vis2k asset's, and more or less the reason Mirror was created in the first place. The numbers measure their performance at the server (not client), in a headless linux build.

    50Hz is the frame rate at the server (not the client). You can set it to 30, which will consume less CPU, but it might increase latency a little bit. It is the tick rate at the server. You can set it as unlimited, which will go as fast as possible, but that really eats up CPU.

    The first number CCU is the amount of concurrent users. Those are bots connected to an uMMORPG server and moving around randomly.

    The second number is the RTT (Latency). How long does it take for a message to go from the client, to the server and back to the client again. This measurement includes not just the base transport latency but overhead from Mirror and uMMORPG. It is meant to reflect real world response time as seen by the user. In other words, if you click on the map, how long does it take for the character to start moving. For uMMORPG, anything about 500 ms degrades user experience. Lower is better

    The third number is the cpu usage. 100% = 1 cpu fully busy. It can go higher than 100% if you have more than one core and your application or unity use multiple threads. Lower is better.

    The 4th number is the total amount of cpu used across all cores. If you have 10 cores and use 100% of one, then you would see 10%. Lower is better.

    The last number is the amount of memory used by the server. Lower is better.

    With telepathy in 2018, you see really bad latency with 450 CCU.
    With booster you see it keep relatively low latency even at 420 CCU. Booster is a proprietary not free transport made by vis2k, which offloads TCP server to a separate process.
    We have improved Mirror/Telepathy considerably and now in 2019, it scales almost as well as Booster in these tests, it is able to keep a relatively low latency even at 420 CCU.

    The improvements are due to lots of work in both Mirror and Telepathy that eliminate allocations and in some cases change algorithms from O(n) to O(1)

    The reason these tests are done with uMMORPG, is that these are not synthetics microbenchmarks showing idealized unachievable conditions, but real world workloads that affect uMMORPG users.
     
    Last edited: Jul 18, 2019
    vis2k and hopeful like this.
  19. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,140
    It still does not change my question. The numbers are useless because they are incorrect. It’s not running at 50Hz like documented.

    Releasing a benchmark showing how many ticks per second each server can manage would be much better.
     
  20. antey3064

    antey3064

    Joined:
    Mar 21, 2016
    Posts:
    15
    How many CCU does uSurvival support on this server? At 50 Hz
     
  21. meeruTheCoder

    meeruTheCoder

    Joined:
    Jul 13, 2018
    Posts:
    8
    Mirror saved my life!!! It's just like UNet, but so much better!!
    Five Stars
     
  22. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,243
    A few months ago we tested it with 200 CCU. Should be able to handle way more now, probably 400 CCU at least.
     
  23. dreamlarp

    dreamlarp

    Joined:
    Apr 22, 2011
    Posts:
    854
    Is there a way to have the server migrate to another client if the host player disconnects like the old p2p system?
     
  24. Refeas

    Refeas

    Joined:
    Nov 8, 2016
    Posts:
    33
    Hi there!
    In my NetworkManager, when establishing the final connection between client and server (handshake) I want to send a big byte array back to the client as a final reply. So I created new NetworkMessage class with a byte[] as a public variable. However, when I try to send the message (it's around 26 MB, it will only be sent once), I get max packet size error. Do I have to split the byte array into smaller chunks and send to the client as multiple messages (in this case it would be around 1600, considering 16K packet size, so I'm not sure if that's a good solution) or is there any way to let Mirror do that for me? Thanks!
     
  25. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,243
    UNET had that feature, but we removed.

    If you are using Telepathy as transport then simply increase the max packet size from 16kb to 26mb. You can find that setting if you select the NetworkManager and look for the TelepathyTransport component.
    Note that the higher the max packet size, the more it opens your server up to allocation attacks where an attacker might pretend to send several 26MB packets in a row, causing the server to allocate a lot of memory for them.
     
  26. Refeas

    Refeas

    Joined:
    Nov 8, 2016
    Posts:
    33
    I only need it for the single large message for each client (it is a 4-player P2P scenario, so attacks should be a non issue here). So it is possible to change the Telepathy packet size at runtime for both server and client and after the message was successfully recevied by the client, set it back to default?

    Edit: So I fiddled around with it, and found out two things:
    1) Setting the MaxMessageSize during runtime has no effect since Telepathy .Client & .Server are initialized during Awake and those properties are never updated
    2) When I created my custom method in Telepathy to update the server & client's MaxMessageSize, the error about message being too big disappeared, but instead I got
    ReadMessageBlocking: possible allocation attack with a header of: 28036081 bytes
    .

    So... is the only safe and proper way to do this to send thousands of smaller messages to the client to put the byte array together piece by piece?
     
    Last edited: Jul 21, 2019
  27. dreamlarp

    dreamlarp

    Joined:
    Apr 22, 2011
    Posts:
    854
    vis2k said:
    UNET had that feature, but we removed.

    Yes, we understand this. But how hard will it be to add it back? We are developing a steam p2p game and would like to make sure that the host player leaving or disconnecting will not close the game. Has anyone else here added this feature back?
     
  28. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,243
    You can still set TelepathyTransport's .server/.client .MaxMessageSize as runtime if needed.

    You could compare with the original UNET code from Unity's bitbucket and add the parts back.
    As far as I know, host migration never worked well though. This is insanely hard to get right because you have to transfer 100% of the server state to another client. It's way easier to just host a few cloud instances so people don't have to worry about host migration.
     
  29. Alexees

    Alexees

    Joined:
    Nov 8, 2017
    Posts:
    189
    @vis2k I don't want to be agressive or anything, but I opened up an issue on Github 12 days ago and nobody seemed to have looked into it. Do I need to provide a fix myself or is someone actively working on fixing issues?
     
  30. stanislavdol

    stanislavdol

    Joined:
    Aug 3, 2013
    Posts:
    269
    @vis2k
    when I try to connect to a server from a webgl, i get this error (itch.io)
    Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.


    I noticed that in your docs websocket transport looks different than the one available.

    There is no Secure tick box or Certificate input fields.
    I assume this is because of https, because when I use a http webpage, there are no issue.
    Is there a way to run it on a https page?
     
    Last edited: Jul 24, 2019
  31. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,243
    Sorry about that. We are working on issues all the time, but we prioritize based on what affects our own game projects first.

    We'll get to yours eventually. If you want to help, try to debug it yourself and see if you can provide any additional info that might help :)

    We are currently working on websockets SSL support.
     
  32. stanislavdol

    stanislavdol

    Joined:
    Aug 3, 2013
    Posts:
    269
    Thanks, any ETA on this?(roughly)

    Also, wanted to confirm this:
    When you set the network frequency, for instance, in NetworkTransform (or any script with syncvars or any syncing),
    0 means send immediately if changed,
    0.5 - twice a second.
    But if it is set to 0.5 and there are no changes, will it send anyway every 0.5seconds or not?

    Thanks
     
  33. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,243
    Please join our discord and talk to katori if you want to stay updated on websockets SSL :)
    syncInterval is in seconds yes. And if nothing changed, then it doesn't sync.
     
  34. Abrasive

    Abrasive

    Joined:
    Jul 24, 2019
    Posts:
    2
    Wow many thanks guys for this networking stuff! :)
    And thanks to "Noob do AAA" website for info about it!
     
    ixikos and vis2k like this.
  35. JWLewis777

    JWLewis777

    Joined:
    May 17, 2015
    Posts:
    64
    Hello,
    Currently researching tools to use for multiplayer and I had a few questions, I looked through the forums and your website but couldn't find the info, is there a FAQ available somewhere?

    I built the pong example and tested on the same machine, worked great.
    Tested it on 2 machines on the same network, worked great
    Tested it on 1 machine on a different network then another machine, opened router with DMZ but couldnt connect.

    Basically is this capable of peer 2 peer on different networks? What about Android to PC? Android to Android? Or will I have to setup a rely server system to accommodate non-lan networking?

    Thank you for any help and so far Mirror looks great!
     
  36. pit-travis

    pit-travis

    Joined:
    Sep 17, 2018
    Posts:
    12
    Sorry if this has been asked before, but is there a way to testing multiple clients (+server) from within the editor, without building the project? Currently I start the server in the editor and run clients as separate apps outside of it, but that's pretty cumbersome as you can imagine.
     
  37. pit-travis

    pit-travis

    Joined:
    Sep 17, 2018
    Posts:
    12
    Additional question: Is there a recommended workflow to have prefabs differ on clients and servers? E.g. an NPC prefab on the server has a NavMeshAgent and is only controlled server side, but the prefab (by default) spawns with NavMeshAgent on clients, too. Is there a better way to add custom scripts to these prefabs that remove/disable certain components on client startup?
     
  38. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    684
    Code (CSharp):
    1. public override void OnStartServer()
    2. {
    3.        GetComponent<NavMeshAgent>().enabled = true;
    4. }
    Please note that in host mode an object will be both client and server, so I would not disable it on client startup because then your GameObject won't work on host mode.
     
  39. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    684
    I don't think so. I always build a stand alone and test with that.
     
  40. Alexees

    Alexees

    Joined:
    Nov 8, 2017
    Posts:
    189
    I wanted to add, if the project is rather big and you're using a versioning system, you can checkout the same project as many times as you need server and clients and then run each in its own editor instance.
     
  41. meeruTheCoder

    meeruTheCoder

    Joined:
    Jul 13, 2018
    Posts:
    8
    What if I want to change the rotation axis for the network transform child? There does not seem to be an option for that, and some other features as well.
     
  42. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,243
    What do you mean exactly?
    You should be able to sync position and rotation without problems.
     
  43. Nullxero

    Nullxero

    Joined:
    May 10, 2015
    Posts:
    1
    Hello everyone! This library looks really awesome but im having trouble understanding some simple things.
    If I want to change the Tanks demo so that a projectile hurts another tanks hitpoints, or changes the position of another tank how do I accomplish this?

    Do I make the Projectile class, which has a NetworkBehavior use its OnCollisionEnter method to fire an RPC and have the RPC make the change?
    Do I just tell the OnCollisionEnter to change the gameobject, expecting the change to be synched everywhere?
    Do I create a new NetworkMessage and use NetworkServer.SendToAll() to send my message of this hit to everyone and process it?

    Sorry but the documentation is confusing on how you are actually supposed to route messages between entities.


    If you update the Tanks example to include the full cycle of firing, damaging, and destroying other tanks it would illustrate through example the proper way of solving these problems, but right now I don't know how to proceed.

    Any insight would be highly appreciated!

    Thanks so much!

    -Ben
     
  44. thesupersoup

    thesupersoup

    Joined:
    Nov 27, 2017
    Posts:
    49
    Can NetworkManager transports be swapped programmatically at runtime? (e.g. using Telepathy for LAN games and FizzySteam for net games?)
     
  45. thesupersoup

    thesupersoup

    Joined:
    Nov 27, 2017
    Posts:
    49
    Commands go from client to server. RPCs go from server to client(s). Clients don’t necessarily need to know the HP of other clients, but that could and should probably be maintained on the server then sent out to the clients from there. Multiplayer data routing should always be client to server, then server to everyone.
     
  46. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,243
    You can use the Multiplexer Transport for that :)
     
  47. thesupersoup

    thesupersoup

    Joined:
    Nov 27, 2017
    Posts:
    49
    Since posting, I did discover and study up on the Multiplexer. I'd like a little more control than for them to both be constantly active. I was wondering if there was some way to manipulate the transport of the NetworkManager, but after discovering the Multiplexer, I shifted toward building my own Transport with a flag I can set to make Available() return false. I basically want to force Telepathy for LAN games, and use Steamworks for internet games.

    BTW, I have a fork of FizzySteamyMirror that I updated for use with Facepunch.Steamworks. It's pretty much just a crude swap-out of all Steamworks.NET code at the moment: https://github.com/thesupersoup/FizzySteamyMirror

    I promptly decided I'd rather build my own Transport though, so I'll be working on another Steam transport using Facepunch.Steamworks as the foundation. I'll post a link here once it's functional.
     
    vis2k likes this.
  48. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    684
    You are on the right track. That will definitely work.

    We have also discussed using urls for connections. For example, if you connect to
    tcp://somehost:port
    it would use telepathy to connect to that host and port, If you connect to
    ws://somehost:port
    it would use the websocket transport. In your case, I would envision something like
    steam://pierid


    We have not implemented it, or reached a conclusion, but this seems like a good way to go in my mind.
     
  49. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,243
    New showcase: Nestables (made with Mirror)!
     
    JohnnyCar likes this.
  50. newlife

    newlife

    Joined:
    Jan 20, 2010
    Posts:
    762
    Hello,
    Im trying to implement multiplayer in my mobile racing game Real Drift Car Racing.
    In order to avoid hacking, I need an approach based on dedicated authoritative server (not listen server).
    Is this possible and feasible with mirror? It seems that mirror is more oriented towards MMO games.
    Can it be used with racing game too?