Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

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,279
    Yes, that's doable. Mirror is server authoritative by default.
     
  2. thesupersoup

    thesupersoup

    Joined:
    Nov 27, 2017
    Posts:
    49
    Presenting MirrorpunchSteam
    I'll be working on it and testing intensely throughout the week. It's likely to have problems in its current state, but it's a start.
    Questions for the more learned:
    • I wanted a way to be able to unregister events for cleaner shutdown, so in the root MirrorpunchSteam I set Action variables to lambda expressions so I could do so. Are there any issues with this approach?
    • How does the NetworkManager handle connection ids, if I'm assigning them in the transport. Is it fairly agnostic to how it routes data associated with connection ids?
     
    MaZy and Refeas like this.
  3. newlife

    newlife

    Joined:
    Jan 20, 2010
    Posts:
    795
    thanks for the reply. Does mirror also support matchmaking and room creation?
     
  4. MonkeyS_Finger

    MonkeyS_Finger

    Joined:
    Nov 11, 2017
    Posts:
    4
    there is a way co connect with another project to a main project network? I wold like to create two different unity projects that use a thirf project as server for sharing data.
    could this be possible with mirror?
    Could you please point me into the right direction?
    thanks.
     
  5. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Latest showcase: Rogue Star Rescue - a roguelike tower defense game made with Mirror!


    It's not in Mirror by default, but you can do that with Mirror.

    We recommend using one project for everything. That's what Mirror was for after all.
     
  6. MonkeyS_Finger

    MonkeyS_Finger

    Joined:
    Nov 11, 2017
    Posts:
    4
    I know that but I need to control some parameters by a different device, and is impossible to make that project work on a very different device.
    So it's impossible to make connect two different projects?
    If I use LLAPI to create a custom socket, do Mirror could have any trouble?
     
  7. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Not 100% sure what you mean. Perhaps our Multiplex transport is useful for you.
     
  8. antsonthetree

    antsonthetree

    Joined:
    May 15, 2015
    Posts:
    61
    Hello - I need to send a collection of structs or classes to a client using TargetRPC. The data is just a string and an int. I am currently planning on doing this as follows:

    Code (CSharp):
    1. class MyThing
    2. {
    3.     string Name;
    4.     int Age;
    5. }
    6.  
    7. void TargetSendData(NetworkConnection conn, List<MyThing> data)
    8. {
    9.     // do stuff with data
    10. }
    My question - Is this the best way to do this in regards to network performance and bandwidth? Should I use a struct instead of a class? Possibly a different type of collection vs List?

    This is not something that will be called repeatedly but I'd still like to keep it as performant as possible.

    Thanks
    Jake
     
  9. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    New Feature: SyncToOwner. Each component can be configured to sync to all observers, or only to owner. This will save large amounts of bandwidth for components like a player inventory, that shouldn't be synced to anyone else. Enjoy!



    You can't send Lists in Rpcs. Only simple types like int, string, bool, int[], string[], etc. and structs like SomeStruct, SomeStruct[], and so on. In your case, simply send an Array and make sure that it's a struct.
     
    akuno, KarlGG, psistalk and 1 other person like this.
  10. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,489
    Hi Does Mirror supports NAT punch through? Also, does it support console platforms? Has anyone shipped a game using mirror on console platforms? Or attempted?
     
    Last edited: Sep 2, 2019
  11. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Check out mirror-networking.com for our showcase.
    Mirror doesn't really care what platform you use it for, they all work.
    Check out our UDP transports, I think a few of them might be able to support nat punchthrough.
     
  12. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    693
    New Feature: Custom readers and writers.

    Since the dawn of time, HLAPI and Mirror have only been able to deal with a limited number of data types. Simple things like passing a DateTime or Uri as parameters in your [Command], [Rpc] or [SyncVar] would give you an error.

    Starting with version 3.17.2 available at https://github.com/vis2k/Mirror/releases, you can extend Mirror and add support for any type you desire. All you need to do do is add extension methods for NetworkReader and NetworkWriters. For example:

    Code (CSharp):
    1. public static class DateTimeReaderWriter
    2. {
    3.       public static void WriteDateTime(this NetworkWriter writer, DateTime dateTime)
    4.       {
    5.           writer.WriteInt64(dateTime.Ticks);
    6.       }
    7.      
    8.       public static DateTime ReadDateTime(this NetworkReader reader)
    9.       {
    10.           return new DateTime(reader.ReadInt64());
    11.       }
    12. }
    There is no reflection involved. The weaver will find your extensions and use them just as if you were writing the code by hand, there is no performance penalty at all. Thanks to @vis2k for keeping me honest and help me find the simplest way to achieve this feature.
     
    Last edited: Sep 3, 2019
  13. francescoStrada

    francescoStrada

    Joined:
    Oct 27, 2014
    Posts:
    4
    Hi, with mirror what are my options of sending RPC to specific clients?
     
  14. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    693
  15. antsonthetree

    antsonthetree

    Joined:
    May 15, 2015
    Posts:
    61
    Hello - I noticed in some of the comments that you have removed a lot of linq code for performance reasons. Can you talk a bit about this? I was not aware that using linq is a performance hit, and a quick google search seems to indicate that it is not. I'm just curious.
     
  16. Refeas

    Refeas

    Joined:
    Nov 8, 2016
    Posts:
    41
    A lot of the Linq functions cause allocations which are pretty performance heavy and can cause big spikes on CPU. You can observe this in the "GC Allocs" column in the Profiler.
     
    antsonthetree and vis2k like this.
  17. Vancete

    Vancete

    Joined:
    May 3, 2010
    Posts:
    180
    Is there a way to get the connected users before connecting to a server? I want to make something like a server list.
     
  18. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Check out our list server: https://mirror-networking.com/list-server/
     
  19. antsonthetree

    antsonthetree

    Joined:
    May 15, 2015
    Posts:
    61
    Hello and thanks for the info. Another question - what about using Async and Await? Is this frowned upon for the same reasons? I seem to recall you guys ditching these functions too. Should I use Coroutines over asyncs?
     
  20. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Async/await is common thing to use in C#. Unity's mono backend however seems to have serious performance issues with that. None of the async/await transports that we tried managed to scale past 100 CCU. It's so slow in Unity that we end up with 120 second latencies.

    If you use a few async/await calls for non-transport stuff then that's probably fine of course.
     
    antsonthetree likes this.
  21. danicolaj2

    danicolaj2

    Joined:
    Sep 10, 2019
    Posts:
    1
    Hi, I can connect clientB to HostA with Mirror, but only in LAN.

    Usually if that happens the issue is that the port is not open/forwarded properly on the modem, but I believe that's not the case: from a unix server somewhere out there in Europe, I "telnet <mywanip> 7777" and telnet connects, ONLY if my HostA is running and listening to 7777, otherwise the connection fails. I believe that proves that I can access hostA through port 7777 from the net, so port is open and properly forwarded.

    Since I'm not a networking expert.... that's pretty much where I grind to a halt.

    To summarize:

    hostA listening on port 7777 - clientB connecting to 192.168.1.33 port 7777 (LAN) - WORKS
    hostA listening on port 7777 - clientB connecting to 312.122.122.111 port 7777 (WAN) - DOES NOT CONNECT
    hostA listening on port 7777 - remote server running "telnet 312.122.122.111 7777" CONNECTS (obviously nothing happens but it connects)
    hostA NOT listening on port 7777 - remote server running "telnet 312.122.122.111 7777" does NOT connect (proving that in the case above hostA:port are reachable from the net)

    help?
    dani
     
  22. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    We usually recommend hosting on Namecheap.com (not because they are the best, but it works without configuration), or Google Cloud (you do need to open firewall ports there though).

    Different hosters might require different configurations.
     
  23. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Showcase: Project Cybertronic

    Previously developed with UNET, now powered by Mirror!
    Check out their website: https://cybertronic.red/
     
  24. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    41
    Ok upgraded from 1095 to latest. Got some problems:

    ClientScene.AddPlayer(conn, msg);
    Cannot convert from Mirror.StringMessage to byte[]


    Whats changed? Having trouble finding the documentation on this update.

    Thanks
     
  25. calvinstreeting

    calvinstreeting

    Joined:
    Jun 14, 2019
    Posts:
    12
    hi.
    can mirror be used to remotly control a main camera
    aka Main Host is full screen window that shows a scene and it lanches (via button or key press) another window (threaded application call) that renders a lesser version of same scene (less graphic quality) that when the camera (orbit control) is moved this changes the camera in the main full screen parent window to match. like a remote control view sub window thingy :)

    just want to know if this is posible (before i start alot of reading and codeing the parts etc.)

    Many thanks
     
  26. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Please post the exact error
     
  27. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    41
    That was the exact error! Don't worry its fixed. Can I suggest though. Stuff like these little network manager changes break existing projects. I hope that changing the AddPlayer from stringmessages to bytes is REALLY REALLY worth it. The great thing about Mirror is that you import it and are not greeted by a sea of red. Important to keep it that way as much as possible IMHO;)
     
  28. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    We try to keep it this way, unless where completely necessary. E.g. in that case above.
     
  29. silverair

    silverair

    Joined:
    Jun 20, 2015
    Posts:
    3
    I'm thinking about a mobile game
    based on a room for 4 player.

    Making them P2P doesn't seem like a good choice.


    So I think I need to manage the server by myself.

    When the player to create room, the master server to run a server process.
    so it's dynamic create server process in each room.

    It's basically the function of Master Server Framework, the Asset.

    But this Asset doesn't seem to support mirror.


    Is there any alternative?
     
  30. Thibault-Potier

    Thibault-Potier

    Joined:
    Apr 10, 2015
    Posts:
    202
    Hi ! I'm a total noob in networking. I'm looking for basics tutorial on how to use Mirror on a unity project. I want to create some LAN multiplayer project (with no internet). Can you point me some good tutorial ? That would be super appreciated
     
  31. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    6,702
    There's not a lot of Mirror tutorials because Mirror is basically Unet and there are lots of Unet tutorials made over the years.
     
    Thibault-Potier and vis2k like this.
  32. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    875
    officialy what's the unity solution HLAPI already drepreced too like unet ?
    thn'aks
     
  33. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    6,702
    See all the sticky threads in this forum. The official Unity solution is currently under development, though there is alpha code released for you to preview, as well as alpha quality documentation.
     
  34. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    875
    i want say lol
     
  35. FuhaoXie

    FuhaoXie

    Joined:
    Nov 18, 2016
    Posts:
    14
    Seems Mirror dont have lan matchmaking, I think it will be very useful to provide a lan matchmaking feature for developer.
     
  36. sth4881

    sth4881

    Joined:
    Oct 1, 2019
    Posts:
    3
    Hi there! I'm interested in Mirror which could replace the UNet! I tried to install it but found a big problem. When adding component like NetworkManager, NetworkIdentity, it was fine but when I tried to make a script importing Mirror and using NetworkBehaviour, 2 kinds of error happens. How should I fix this bug? upload_2019-10-10_17-32-59.png
     
  37. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Someone sent us a pull request already: https://github.com/vis2k/Mirror/pull/1024
    We are still considering it. Feel free to try and let us know if it works for you.
     
  38. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,279
    Looks like you didn't import it properly. Go to the Unity Asset Store, search for 'Mirror', get it from there, try to extend our examples.
     
  39. FuhaoXie

    FuhaoXie

    Joined:
    Nov 18, 2016
    Posts:
    14
    Another issue is ,when I attach unity using vs first, and then start editor. the editor will freeze even I dont set any breakpoint on it. This editor freeze always happen when attaching the editor
    My unity is 2018.4.4f1 and vs 2017.
     
  40. tranos

    tranos

    Joined:
    Feb 19, 2014
    Posts:
    142
    Hello to all! I want to make registration and login for Lan. Username and password will be stored in the local server. How can I use Mirror to do that? Thank you.
     
    Last edited: Oct 10, 2019
  41. digiross

    digiross

    Joined:
    Jun 29, 2012
    Posts:
    235
    I'm starting a new project and this will be my first game with multiplayer. I've recently been wading through all the multiplayer options and Mirror looks like the path I need to take.

    My game will feature lobbies of 10-20 players and projected playerbase in the 3-5k range monthly. But who knows it could take off even bigger.

    For my scalable cloud servers, I've checked out Amazon AWS and it seems pricey for an indie. Is there a better alternative? I found 2 others that seem to offer a similar service, the first being Hostwinds.com and the other Vultr.com.

    Anyone's thoughts and recommendations would be appreciated.
     
  42. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    6,702
    With the cloud services you're paying a premium for convenience and redundancy. Spending a while looking for the best deal in price to the resources you get, it is pretty clear the best deal is if you rent somewhat outdated dedicated servers. For example, for my game I pay $65/mo for 16 cores of Opteron 4284, 32 GB RAM, 2TB HDD storage, and 25TB data transfer. If you used a similar amount of resources from AWS the cost would be considerably higher ($1k maybe?). Check out Joe's Datacenter (no affiliation with myself other than being a customer, regardless of my username).

    The big negatives are you are unlikely to fully utilize all the available resources of a dedicated server every month, and a dedicated server is more prone to going down for a hardware failure than a cloud virtual server, since cloud servers can be moved between physical hardware as needed seamlessly. But depending on your game, renting multiple dedicated servers may actually save you a considerable amount of money than going the cloud route. YMMV
     
    Willbkool_FPCS, digiross and TwoTen like this.
  43. digiross

    digiross

    Joined:
    Jun 29, 2012
    Posts:
    235
    @Joe-Censored you confirmed part of what I was thinking by going the mirror route. The dedicated server you have, how many players could you reasonably expect to support. For instance, say you have a 16 player game, how many instances would it support so I could guesstimate how many servers I would need depending on game sales/popularity. That seems to be part of the factor as to why people are going balance loaded cloud servers these days. Not to mention the dependability/redundancy you already mentioned.

    Adding multiplayer definitely magnifies the issues compared to singleplayer. :eek:
     
  44. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    6,702
    That's a very difficult question to answer, as it depends entirely on your game. A card game or simple turn based game for example, you might be able to support thousands of users. A very high speed game requiring lots of CPU or memory resources though might bottleneck you there with relatively small numbers of users before network usage even matters though. Run your server instance on your home machine in headless mode and look at its resource usage to get an approximation for how many of it you can run on your server.

    You could also consider using dedicated servers for your expected capacity needs, and spinning up cloud servers as needed when demand exceeds capacity.
     
    Last edited: Oct 12, 2019
  45. digiross

    digiross

    Joined:
    Jun 29, 2012
    Posts:
    235
    Thanks for the insight! :)
     
  46. FuhaoXie

    FuhaoXie

    Joined:
    Nov 18, 2016
    Posts:
    14
    Is there a quick Relieable UDP solution in mirror?
     
  47. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    303
    There are a bunch of different transports for Mirror, including two that are UDP-based.
     
  48. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    303
  49. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    693
    The mirror profiler is now available to all our patreons

    You can easily find out what objects are sending what messages and tune your bandwidth utilization.
    Read the documentation for instructions as well as suggestions for improving your game.

    Some key features:
    • Simple and intuitive, just open it and press record
    • Inbound and outbound messages, even your own messages
    • Sort the messages by any field
    • Shows chart by message count or by total bytes
    • Zero overhead if you are not using the profiler
    • It can save and load profile data
    • Show all frames or only frames with messages
    • Displays name of your commands and rpcs
    • Displays the object that sent the command, rpc, syncvar or being spawned
     
  50. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    376
    Is here any Playmaker actions available for this asset?