Search Unity

  1. Click here to receive a gift with your purchase of Unity Pro or Unity Enterprise.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Unity Multiplayer Mirror - Open Source Networking for Unity

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

  1. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    435
    As someone who's been quietly admiring you guys for a long time and is hesitantly thinking about making networked experiments, where do I sign up to help with those CCU tests?
     
  2. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,712
    But why? I don't understand the problem that you are trying to solve.

    Join our discord!
     
  3. antey3064

    antey3064

    Joined:
    Mar 21, 2016
    Posts:
    15
  4. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,712
    Recently tested 250 and 500 CCU in uMMORPG successfully. So I am not worried about uSurvival's networking at all right now. uSurvival is meant for games like Dayz/Fortnite, which both only support 100 CCU.

    In other words: if the networking can handle uMMOrpg then uSurvival will always be fine.
     
  5. YuriPetskus

    YuriPetskus

    Joined:
    Jun 22, 2018
    Posts:
    16
    My scene contains 2600 NetworkIdentity objects (game like Minecraft).
    When the client connects, the scene takes more than 10-15 seconds to load and the UI is not responding at this time.

    I started using NetworkProximityChecker. Loading the scene has become faster, but when the player first moves around the scene, the game periodically freezes for 1-2 seconds.

    I think it's because NetworkConnection.HandleBytes () calls ClientScene.OnSpawnPrefab () synchronously.

    Is there a way to spawn scene objects asynchronously?
    Every frame, for example.
     
  6. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,712
    Is every voxel a networkidentity? Try making each chunk a NetworkIdentity instead.
    Also try a proximity checker that is grid or chunk based to avoid Spherecasting each time.
     
  7. YuriPetskus

    YuriPetskus

    Joined:
    Jun 22, 2018
    Posts:
    16
    My proximity checker is simple
    Code (CSharp):
    1.         public override bool OnRebuildObservers(HashSet<NetworkConnection> observers, bool initial)
    2.         {
    3.             // only add self as observer if force hidden
    4.             if (forceHidden)
    5.             {
    6.                 // ensure player can still see themself
    7.                 if (connectionToClient != null)
    8.                 {
    9.                     observers.Add(connectionToClient);
    10.                 }
    11.             }
    12.  
    13.             foreach (NetworkConnection conn in NetworkServer.connections.Values)
    14.             {
    15.                 if (conn.visList.Contains(this.netIdentity))
    16.                 {
    17.                     observers.Add(conn);
    18.                     continue;
    19.                 }
    20.  
    21.                 if (conn.playerController == null)
    22.                     continue;
    23.  
    24.                 if (Vector3.Distance(conn.playerController.transform.position, transform.position) < visRange)
    25.                 {
    26.                     observers.Add(conn);
    27.                 }
    28.             }
    29.             // always return true when overwriting OnRebuildObservers so that
    30.             // Mirror knows not to use the built in rebuild method.
    31.             return true;
    32.         }
     
  8. YuriPetskus

    YuriPetskus

    Joined:
    Jun 22, 2018
    Posts:
    16
    It's not voxels basically.
    Each brick is NetworkIdentity and it lies in a free position. There is no chunk actually.

    Something like this
     
  9. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,712
    For each networkidentity you are comparing the distance to each player on the server. This is huge amount of computations as soon as you have more than a handful of players.

    The built in proxchecker is probably still faster if you set the cast layers to your player layer.

    I recently added a grid checker to my assets, which is 30x faster than the built in proxchecker again. It simply divides the world into grids and adds all the players in your grid + 8 neighbor grids to observers.
     
  10. antsonthetree

    antsonthetree

    Joined:
    May 15, 2015
    Posts:
    75
    Found a bug - When you spawn an object on the server with a parent, the parent is never sent to the clients. I looked thru the code and I don't see anywhere in NetworkTransformBase where the transform parent is being synced with the clients.

    You can repro this by spawning an object on the server and giving it a parent.
    GameObject theThing = Instantiate(somePrefab, Vector3.zero, Quaternion.identity, someParentTransform);
    NetworkServer.Spawn(theThing);

    Then check the client and you will see theThing does not have a parent.
     
  11. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,712
    NetworkIdentities don't work properly if they are parented. They should always be the root GameObject.
     
    Joe-Censored likes this.
  12. antsonthetree

    antsonthetree

    Joined:
    May 15, 2015
    Posts:
    75
    Hello - I am not seeing these shiny new features in the latest Network Manager. Do I need to do something to enable them or is this a "coming soon" feature?
     
  13. VrTechEx

    VrTechEx

    Joined:
    Aug 4, 2013
    Posts:
    36
    I mean when someone already picked an object in the game and then a new player joins in the game. The new player didn't see the previous player picked the object up.
     
  14. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    722
    Drag in the WebSocketTransport into your networkmanager gameobject. The transports are now just components you drag in.
     
  15. Tyrannmisu

    Tyrannmisu

    Joined:
    Oct 23, 2018
    Posts:
    4
    Maybe i am just stupid, but i cannot get networked scene gameobjects to work....
    I just switched from UNet to Mirror and it went mostly fine.

    I happen to have some objects in the scene that have network identities and syncVars. It all works great for the host, but the game objects in question are never enabled for any client.
    The game objects are not parented and it worked fine with UNet.

    I am able to reproduce this behaviour with the basic example, that is included with Mirror.
    Just add an instance of the player prefab into the scene. The additional text will be shown for the host but the GameObject will never be enabled for the client, therefore it will never see the text.

    The log looks like this:
    • DEBUG: TelepathyTransport initialized!
    • WARN: Could not find scene object with sceneid:1431655766
    • ERROR: Spawn scene object not found for 1431655766 SpawnableObjects.Count=1
    • DEBUG: Spawnable: SceneId=1 name=FakePlayer
    Followed by multiple (because it stays disabled):
    WARN: Did not find target for sync message for 1 . Note: this can be completely normal because UDP messages may arrive out of order, so this message might have arrived after a Destroy message.

    I am testing on the same machine by connecting to localhost. Unity version is 2018.2.20f1.
    Mirror is version 1.4 (installed via the asset store)
    I tried to find a solution in this thread and in other places too, but i cant seem to find any.

    Edit:
    I tried to debug the issue on the client and ended up in ClientScene.SpawnSceneObject.
    The actual key for the game object in spawnableObjects is 1 but for some reason it tries to access it with the sceneId 1431655766

    Edit2:
    Okay ... it works if both (host & client) are a build version. If one of them is started via unity it stopps to work. This makes debugging a little hard. :D
     
    Last edited: Feb 6, 2019
  16. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,712
    Please open an issue on our github page and tell us exactly how to reproduce it
     
  17. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    335
    Or come visit the Mirror Discord and we can try to see what went wrong.
     
    vis2k likes this.
  18. Yokimato

    Yokimato

    Joined:
    Oct 9, 2012
    Posts:
    8

    I also ran into this issue -- a (very helpful) developer on their discord got me sorted in quick order though. The problem stems from having scenes in the build settings that are disabled causing an index offset problem. Once I simply removed scenes that are not in the build, everything worked as expected.
     
    vis2k likes this.
  19. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    455
    I am working on a single player iphone game where a player plays volleyball against a computer player. I'd like to turn it into a multiplayer ios game.

    I have not made a multiplayer game before, and am still learning about the subject, watching tutorials, reading documentation etc. I couldn't find the answers after looking through the forum and reading about Unet, mirror, and Unity's upcoming projects. Mirror seems really easy to understand and use, but I still can't figure out if it's the right technology for this project.

    Questions:
    1. Is it possible to turn an action physics based iphone game into a multiplayer game using mirror?

    2. I see mention of TCP with latency of 60ms but not sure what type of connection these numbers come from: wireless, LTE, direct connection, peer to peer?

    3. Can a mirror game be hosted by Unity Services, or do you have to setup your own servers?

    4. If there's no matchmaking services in mirror what solutions are available?

    5. Is mirror the wrong technology for this sort of project? If not what is?
     
  20. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    235
    @dansav
    For a 1on1 game you could use a nodeJS server and socket.io, put the two players in a room and send basic events (player/ball movement, etc)
     
  21. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    958
    Another beginner with a simple question, I am in the process of doing a racing game and want to start adding multiplayer support, is Mirror suitable for basic racing game or is it overkill?
     
  22. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,712
    Try and see :)
    There is no specific code that would prevent it from working in a racing game.
     
  23. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,712
    Progress: Finally fixed the annoying "(Clone)" suffix when spawning objects. This is huge for games that show the name above the entity's head, e.g. MMOs. This way we need no more NetworkNameSync component on monsters. Should offer a significant bandwidth improvement, e.g. when spawning 1000 monsters near a player.

     
  24. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    760
    Hilarious.
     
    Vincenzo and kfng like this.
  25. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,249
    Just starting with Mirror and as I would like to to use UDP I have also added the Ignorance Transport system but when I imported that system I get the error:
    Assets\Mirror\Transports\Ignorance\IgnoranceTransport.cs(225,30): error CS0115: 'IgnoranceTransport.GetConnectionInfo(int, out string)': no suitable method found to override

    Did I mess up the copying? Or do I need certain versions of each system for them to work.

    Also what is the situation regarding NAT punch through with Mirror? Do I need another asset for that?
     
  26. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    722
    That method was added in mirror yesterday, Ignorance needs to be updated with it @MCoburn
     
    Last edited: Feb 21, 2019
  27. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,712
    News: after all the hype around ENET, we decided to test it in a real world scenario. After all, not worrying about a battle tested transport would be great. Especially since ENET was used by league of legends, and virtually anyone loves it on this forum.

    Setup: uMMORPG, 16 core server, ENET via Coburn's Ignorance Transport, which uses nxrighthere's ENet-CSharp as backend.
    upload_2019-2-19_14-5-43.png

    Results:
    upload_2019-2-19_14-5-59.png

    2-3x latency up to around 250 CCU. Then latency spiked really high and my local client received no more updates. Then everyone disconnected for some reason. My guess is that ENET's peer timeout of 5000 ms was reached.
     
    goldbug likes this.
  28. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    760
    You should check this. My 5k CCU demo (64 tickrate, 320000 messages per second). As being said, your library is inappropriate thing to use in game dev. You will never reach 5k CCU with your "fake" mmo scalable asset.
    My spec: core i7-7700k (4 cores, 8 threads), 16gb ram.

    Good luck.

    https://forum.unity.com/threads/showcase-enet-unity-ecs-5000-real-time-player-simulation.605656/



    EDIT: why did you delete your posts with your "benchmarks" of ENet library?
     
    Last edited: Mar 14, 2019
  29. ComputerCables

    ComputerCables

    Joined:
    Jun 21, 2017
    Posts:
    4
    Can i see the SyncListStruct examples? I'm lost and the documentation shows very little.
     
  30. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,712
    Sorry if I stepped on any toes here, but if we want to use the scientific method then we need to leave egos and personal insults out of it. It's just a benchmark.
     
    Last edited: Feb 19, 2019
  31. blacksun666

    blacksun666

    Joined:
    Dec 17, 2015
    Posts:
    192
    Couple of questions about the above benchmarks.
    Were these measurements taken on the backend and was it running headless?
    What is the 'magic' transport?
    Why was the profiler/benchmark reporting unable to measure the load/response when using the 'magic' transport when pushed under load?
    Is it uMMORG that causes the main core of the cpu to max out but the other cores are only lightly loaded or the networking; if the later is it mirror or the low level transport that is at fault?
     
  32. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    760
    Your benchmark is a complete fail.
    The only toe you step on here - is yours.

    The claim that ENet performs worse is false as well as many others claims made by you here, on forum. I wish your account got banned for distributing false information but sadly, it will not happen.
     
    Last edited: Feb 19, 2019
    NoobDoAAA and nxrighthere like this.
  33. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,712
    Headless Linux (Ubuntu). Measured via 'top' command on server.

    Magic transport connects to an external load balancer that handles TCP connections. It can scale to >100k connections, but it's not like Mirror or Unity could handle as many players anyway. It's called 'magic' transport because there is some magic involved to set it up, which is why we are still looking into other transports like ENET, which would work out of the box.

    That was a user error. I forgot to write them down after a 20 hour day. Here are the results from another version of 'magic' transport:
    upload_2019-2-19_23-45-36.png
    This version was even faster, but it uses UDP for Unity<->Loadbalancer connections, which made the code more complicated. The TCP version from the original benchmark is slightly slower.

    'magic' transport is fully uncorked so to speak. Mirror&uMMORPG both run on Unity's main thread, which is where we have to focus our optimizations on now. In other words: we are definitely Unity main thread limited now.
     
  34. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,712
    Why?
     
  35. Gyrase

    Gyrase

    Joined:
    Sep 7, 2018
    Posts:
    3
    It's because the benchmarks are not comparing like for like, and the Magic/load-balancer combination shouldn't be included.

    Which is being tested, low level or high level?
    Really, if comparing low to low the same high level abstraction layer should be used, ensuring it's a fair comparison.
    It's fair to say that the combination doesn't work well, but that's a different statement to what was implied.
     
    nxrighthere likes this.
  36. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,712
    All the tests use the same uMMORPG + Mirror high level abstraction.
    The only difference is the low level transport. Which results in different benchmark results.

    They are comparing low level transports. What do you mean?

    Why? The goal of the benchmark is to show latest transport research.
     
  37. Gyrase

    Gyrase

    Joined:
    Sep 7, 2018
    Posts:
    3
    To make it *fair*, and like-for-like, the number of variables should be reduced.
     
  38. Deleted User

    Deleted User

    Guest

    @vis2k two short questions since this thread is quite long:
    - is Mirror capable of being built successfully to UWP, MR and Hololens using IL2CPP (as NET is deprecated now)
    - Does it fix the problem of rebuilding client and server all the time even if the change was just a comment in NetworkBehavours?
     
  39. blacksun666

    blacksun666

    Joined:
    Dec 17, 2015
    Posts:
    192
    @vis2k could you document the version information using in your benchmark for mirror and the low level transports. There is obviously some discrepancy between using ENet and using ENet with mirror and I'm wondering where the problem is and if it has already been fixed?
     
  40. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    722
    @Gyrase we are trying to find the best transport for Mirror. This is not an attack on enet, we want it to perform well so that we can use it more widely. We don't want to make transports, we would have stayed with LLAPI if it worked. We would throw away Telepathy in a heart beat if we find something better.

    The number of variables is exactly the same in both cases. The only difference is the transport.

    Forget about "magic", it is not released, and it is obnoxious to set up. It will never be merged in Mirror; at best it would be an add-on. We are interested in a transport that can beat Telepathy at this moment.

    If there is some configuration we are missing, or some obvious problem in our test, or if you want to test it yourself, please let us know.
     
    Last edited: Feb 21, 2019
    hopeful likes this.
  41. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    722
    Yes, Mirror works in those platforms. I have not tested it myself but I know people have reported success.
    I am not aware of the problem you describe, could you elaborate? Is that an HLAPI bug or was that a Mirror bug at some point?
     
  42. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    760
    For everyone,

    I would personally suggest to avoid such things as Mirror, Telepathy, Ignorance for various reasons.
    All of three things are not suitable for production or even hobby projects.
    For anyone who would like to know the reasons - you are welcome to drop me a personal message.

    Cheers.
     
  43. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,712
    It used the latest Mirror version, latest Telepathy version and Ignorance 1.2.0rc5 as well as the ENET-CSharp version that comes with Ignorance. This was our first ENET test, we plan to do several more with improved Ignorance versions and with original ENET instead of nx's version.
     
  44. Vincenzo

    Vincenzo

    Joined:
    Feb 29, 2012
    Posts:
    136
    I don't really see the point that you wish to change the Enet version, the original one is slower, has more bulk and doesn't have IPV6 support, but by all means try it out.
    The real reason this test was failing is because the implementation (aka Ignorance) of Enet in your library is bad. I explained you the problems with it on discord but the developers seemed like it would be "too complicated" to fix it. even when i exactly explained how to do it.

    Don't spread false information here to people that somehow Enet is inferior to other solutions, because benchmarks have shown that it can handle a lot thrown at it, thousands of clients.. Because it's so simple and straight forward.. just check the code if you can read C,

    I really enjoy the fact that people took up the stick from Unity to fix their HLAPI and help the average small time developer with no networking skills to get his project working with networking, that's great, but you as a head of it Vis2k, that is just not the right path.
    Your all the time trying to defend your work, and weird decisions, like advising people to use a TCP protocol for fast paced multiplayer games.. Even worse, make a TCP library that spawns 2 thread per client and doesn't close them gracefully, once a server runs for a while you have a few hundred threads running.. That is not how CPU's like threads, there will be cache misses, there will be needless context switching.. It's a terrible implementation.

    The biggest problem is not listening to suggestions nor accepting clever PR's on your repository that would improve performance or add functionality that could be used to improve performance.

    The simple concept of a GC free library seems beyond you, whilst you push for LINQ in the hot path, foreach loops. and other things because its "simple and stupid" which is the most silly comment i ever seen. I mean this is basic stuff, were dealing with the Mono run-time of unity here, with a dated Boem GC..

    Like you said yourself, your single thread bound on your library, no big surprise there, but your denying any fixes for it because they are supposedly "magic" and in your eyes less code is better, which makes no sense at all.

    I would very much support this project and add a few PR's if things would be accepted, but I don't see that happening, and right now this Mirror, is actually a trap for developers trying to go from HLAPI to something better, perhaps porting their projects. And that saddens me greatly, Our community needs progress not regress.
     
  45. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,726
    No personal attacks.

    People are welcome to post counter claims or evidence and mature discussion but personal insults are directly against the rules.

    Do not reply to this mod note.
     
    nirvanajie, goldbug and hopeful like this.
  46. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,712
    Maybe you are right and it is slower. Networking is very difficult though, we need to try things in production to find the best solution for us.

    Despite the flawed two-threads-per-connection design, there is only one reason why Telepathy is still the default for Mirror: it performs best in our real world tests. I don't like it either, but it is true. I tested a handful of different TCP implementations ranging from simple async-await, to BeginSend/EndSend, to SocketAsyncEventArgs. Both async-await and SocketAsyncEventArgs significantly outperform Telepathy when running tests outside of Unity, e.g. in Visual Studio or Rider. Once we put them into Unity, we see 120 second latency after 50-100 CCU. I'd much prefer the SocketAsyncEventArgs code because it's actually very elegant. But in Unity, Telepathy still outperforms the others and we have to use what actually works best, not what we think works best.

    That being said, we are improving and testing our different transports every day. Something else will beat Telepathy eventually, but the only way to find it is to benchmark everything in production. I don't understand how people can get personally offended by that. It's not like I wanted to do Mirror or Telepathy. The reason why I picked UNET for uMMORPG was so that I didn't have to worry about networking. But when the UNET team abandoned us, no one else wanted to do it.

    Original UNET had 21129 lines of code. We simplified and cleaned it up to reach 11077 lines of code, or in other words: almost half of it. We did not accept many GC optimizations yet in order to focus on cleaner code and better algorithms instead.

    People have been criticizing us for that since day one. But not only did we remove a lot of unnecessary allocations from the original code, we also made significant improvements to the high level algorithms. In many cases we were able to change UNET's O(n) algorithms to O(log n), or similar.

    As result, we scaled UNET's original 50-100 CCU to Mirror's 500+ CCU. An order of magnitude improvement, due to algorithm improvements.

    We are not against GC, but decided to focus on high level code optimizations first. The benchmarks seem to confirm that decision.
     
    Last edited: Feb 20, 2019
  47. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,726
    Well, I'll just point out that there isn't anything more efficient than DOTS / ECS. Blizzard use it, Riot uses it, Unity is working on Using it, and even Photon is now using it with Quantum.

    Personally, I'm going with one of the ECS options because that's scientifically proven to be the best. I do think people should learn to live and let live though.

    Each to their own, but don't pretend this solution will come close to a DOTS/ECS solution though (nothing will, since it mirrors how CPUs work and determinism by default is around the corner).

    So to answer your question - you are doing something right if it is about the coding style you prefer. If you mean "what is the most efficient already proven by science" then that prize goes to anything ECS based. According to blizzard who do it right more than anyone else does.
     
  48. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,712
    Fair enough. Some people like ECS, we still like MonoBehaviour. ECS is obviously faster, no doubt.
     
    hippocoder likes this.
  49. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    722
    ECS is clearly faster, I don't think anybody ever claimed otherwise. But it is so darn difficult to use that it is borderline unusable for muggles. Hopefully they improve usability in the future.
     
    Gekigengar, hwaet and hippocoder like this.
  50. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    760
    I guess it is difficult for you because it needs some knowledge in multithreading and architecture of modern CPUs. And of course switching from OOP to DOD means to write more lines of code which you and vis2k are afraid of.

    Here is a good example of why you guys will never advance yourself:



    500 kb of GC and 400ms to calculate zone of insterests.

    Ridiculous.
     
    Last edited: Feb 20, 2019
    hippocoder likes this.
unityunity