Search Unity

Showcase Mirror - Open Source Networking for Unity

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

  1. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Set Transport.layer = new LLAPITransportLayer to use old UNET's UDP LLAPI. Or make your own layer (see mirror source code -> Transport folder).
     
  2. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    You can use any low level networking backend that you want.
    Also, I think people greatly underestimate networking speeds in 2018. Ten years ago when we played counter strike, anything lower than 80ms latency was really good.

    These days I have 20ms latency if I ping google, and I doubt that a TCP based shooter would have more than 60ms latency on average there.

    But then we might as well start discussing religion or linux vs. windows here. Use which ever backend you prefer, that's fine :)
     
  3. sirwhatevers

    sirwhatevers

    Joined:
    Aug 25, 2017
    Posts:
    33
    Yea, I get that. Maybe I wasn't clear on what I'm wondering. From what I understand, the LLAPI can send reliably or unreliably. How do we specify in Mirror how we want something sent?
     
  4. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    769
    For now you can't. All messages are fragmented, ordered, reliable.

    Other people are also asking for this feature, so pull requests are welcome.
     
  5. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Take a look at the Mirror source code -> Transport -> LLAPITransport. The constructor has an optional global and connection config where you can pick your one channel to use.
     
  6. sirwhatevers

    sirwhatevers

    Joined:
    Aug 25, 2017
    Posts:
    33
    Okay, this library won't work for me then. I'll have to hold off until support for more than just one method of sending is added.
     
  7. Lleot

    Lleot

    Joined:
    Mar 27, 2014
    Posts:
    2
    I know this is bit of an ask but could someone make an example project that is just 2 balls with rigidbodies? So one player controls one ball and another player controls another ball and they can collide etc.
     
  8. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You should be able to use any existing Unet tutorial or example with just minor modification.
     
  9. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    We are about to release a simple pong example. Until then check the UNET manual, it's still mostly the same except for 'using Mirror' instead of 'using UnityEngine.Networking'.
     
    Joe-Censored and ZDM1998 like this.
  10. Jacky2611

    Jacky2611

    Joined:
    Mar 2, 2013
    Posts:
    12
    Have you ever thought about implementing some form of horizontal scaling?
    It's been a few years since I last used UNET and as far as I could tell back then the only thing it was good for was implementing some form of local coop or small-ish (4-16 players) mp games. I ended up writing my own server using java (why I picked java is beyond me) and some libraries just so that I had servers that could display other server's objects, hand authority over to each other and all work with the same entity-id cache. I think I gave up when I had to figure out a way to load balance my cache.
    Assuming Mirror is similar to what I experienced when I tried unet back then I am afraid that it might be a bit tricky to move entities and clients between servers without some form of support from Mirror.
     
  11. II_Spoon_II

    II_Spoon_II

    Joined:
    Jun 16, 2018
    Posts:
    180
    Hello, I am a noob at networking..:3 I am working on a 1 v 1 RTS game right now, is mirror gonna work fine for that?
     
  12. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    RTS games generally use a networking technique referred to as lockstep. The Unet HLAPI, and hence Mirror, operate fundamentally differently than lockstep. I'm sure it is possible to use Mirror in an RTS, but I'd research what other RTS developers have been doing and their reasoning behind it.
     
    II_Spoon_II likes this.
  13. II_Spoon_II

    II_Spoon_II

    Joined:
    Jun 16, 2018
    Posts:
    180
    Yeah I am aware of that, the problem is I didn't any good framework for that :/ and I don't know much about networking to create my own solution.. :/
     
  14. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Check out the benchmark videos on the first page. Mirror can handle hundreds of players now, definitely not only 4-16 players.

    As for moving then through servers: you would simply write to your database, tell the player to disconnect and connect to the other server and then the other server would load the player from the database again. I do this with my NetworkZones addon for uMMORPG already.

    I think Mirror is the easiest way to get started. There is no easy way to do lockstep in Unity right now anyway.
     
  15. Jacky2611

    Jacky2611

    Joined:
    Mar 2, 2013
    Posts:
    12
    The problem with writing and loading to a db would be that there is no seamless transition between zones. Clients can't see across the border, NPCs wouldn't be able to cross and there is no way to easily split a specific zone at runtime should more players than expected join.


    @II_Spoon_II Hardly anyone still uses lockstep. It was great to cut down traffic back when the internet was a lot slower, but your entire game would have to be 100% deterministic. (Unity physics and pathfinding, for example, are not deterministic) In addition, everything starts falling apart the moment you have just a bit of lag. And joining an already running game usually takes a while because your computer has to simulate every single turn starting at the beginning of the game.
    Today most games use a simple client-server solution. With Mirror it is probably even possible for a client to be the server at the same time.
     
  16. Saturn1004

    Saturn1004

    Joined:
    Nov 14, 2014
    Posts:
    42
    I hate to ask noob questions, but I did a search and didn't see an answer to this.

    (background)
    I'm trying to convert an existing server/client that uses the absolute basics of Barebones Master Server Framework (which uses UNet) to Mirror, the only part I actually ended up using of MSF is connecting and sending my own custom packets back and forth.

    The issue I have when trying to convert from UNet to mirror is important stuff like:
    NetworkTransport.Init();
    No longer works when using UnityEngine.Networking is replaced with using Mirror;

    So, my question is: What does Mirror use as an alternative to UnityEngine.Networking.NetworkTransport?

    I wish I didn't have to ask on here. If there was a Mirror example project available that just had client + server connecting, packethandlers set and just a simple string packet being sent from server to client saying "I'm connected!", that would be extremely helpful and I could figure out the conversion myself.
    Thanks!
     
  17. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    You don't need NetworkTransport.Init in mirror. it does that automatically.
    Take a look at the mirror source code -> Transports -> TelepathyTransport.cs
     
  18. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
  19. felipemuniznet

    felipemuniznet

    Joined:
    Jun 5, 2018
    Posts:
    6
    is it possible to de-register the client server? I do not think it's safe to send server binaries to the client, it's very simple to decompile the dlls, I usually create a standalone tcp server with .net core, and I can reuse some business rules classes from some dlls with unity using .net standard , but the server logic gets completely de-logged from the client.
     
  20. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Getting a project done quickly and in a reliable way is as good a reason as any.
     
    mischa2k likes this.
  21. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    You can hide server code on the client with #if SERVER etc. if needed.
    But even if the client knows all the server code, it doesn't make it less safe. You can see all the source code from the operating system that that server runs on too, yet it's unlikely that you will hack linux.
     
  22. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    Congratulations on releasing both Mirror and Telepathy. I am starting a new project with Mirror (fresh project) and in it there are quite a few stats that need to be tracked (about 20 or so); strength, agility, etc...

    Originally I used SyncVar but quickly it felt counter productive and looked really bad having 20+ variables with SyncVars and having to do operations that involve them all meant typing them all manually over and over. So I resorted to using SyncListStruct, something I never understood how it works in HLAPI and was bugged anyway.

    Now I setup the struct like the documentation says here. But I am unsure how it really works? Does it auto-sync on change like SyncVar and I need a hook to display changes in the UI for example? Do I sync them manually? If so, how?

    I tried to read the documentation but as you can see anything about them is badly written and doesn't even come close to documentation. Would you mind explaining (or anyone that knows how they work) ELI5 how they work and how do I use them?

    Thanks.
     
    mischa2k likes this.
  23. Deleted User

    Deleted User

    Guest

    I understand, even if I wanted to use Mirror with a tcp server out of unity, would I? the unity still has a lot to evolve when it comes to .NET, with the 2018 version it brought the .net standard but even so they have many libraries that are not supported, I prefer to work outside it with .net core.
     
  24. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    synclists sync after each change
     
  25. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    I see thank you very much.
     
  26. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,533
    What about a hybrid approach, where UDP is used for player movement, and TCP for everything else? As someone who has played both wow and minecraft and hosted a server the later for a long time, anyone on a wifi connection or even a tiny bit of packetloss at times would have complaints about the lag, even ping times above 200ms would be problematic.. most noticeable was player movement.. to me if feels like while I agree with the position of just getting things working and not wasting a lot of time on missing information ... anything that involved sending constant updates in player position updates is something that would definitely be better done on UDP especially when player position also effects player camera in a first person perspective, while just about everything else could be done on a TCP layer. For mmo type games where it's spellcasting, third person camera at a distance, etc ..no twitch, aim accuracy factors.. yeh no brainer to use TCP, but for FPS type games.. TCP can be a little bad.. It will be interesting how your other asset uSurvival which I got for fps example goes.. but personally I think a hybrid approach would be great to see specifically where UDP is used for a movement layer, that way what a player see in position updates for other players and there own position is lot more accurate without delays and rubberbanding etc.. everything else TCP? well those are my thoughts on it.
     
  27. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    769
    You are welcome to make it, the code is MIT licensed.
     
  28. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    For my own networking API I considered this, but was at a loss how to best deal with cases where you've got a successful connection on one of the two and either a failure or disconnect on the other. It also would be basically two separate transport systems, since TCP is connection based while you have to build your own connection system on top of UDP separately. It just didn't seem very clean the more I looked into it.
     
  29. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    769
    I agree, in theory it sounds great, best of both worlds. In practice it is very complicated with weird corner cases.

    It is probably easier to use one of the existing RUDP libraries that already do all of this.
     
    Last edited: Sep 14, 2018
    Joe-Censored likes this.
  30. Loden_Heathen

    Loden_Heathen

    Joined:
    Sep 1, 2012
    Posts:
    480
    Just saw Mirror here as I was digging around the info on UNET deprication plan.
    We use Steam Networking hooked up to UNET HLAPI for ease of use and wondered if similar could be done with Mirror
     
  31. YureiApps

    YureiApps

    Joined:
    Jan 12, 2015
    Posts:
    5
    Hi, a couple days a go I've updated my unet project to mirror.
    I'm testing the game over the lan network on 4 pc.
    Everything seems to work fine, but sometimes there is a delay on actions.
    I try to explain myself better with an example.
    If the client1 is moving and shooting bullets, all the clients see what is happening, but sometimes the client 1 that is shooting stop to move for all the other clients for about 1/2 seconds, and then he send again positions.
    This is more evident when a client is firing bullets, if the client 1 is shooting (The bullets are managed by server) when the "PAUSE" happens no one see the bullets, and after 1/2 seconds, all the bullets are spawned all toghether with the original directions.

    seems that the mesages stop to travel and goes in a kind of a queue and then will be sent all together.

    can someone help me with this weird behaviour?
    maibe there is some settings that I can tweak? or maybe could be a router configuration or firewall problem?

    I hope someone can help me, becasue i'm loosing my mind on this thing.
     
  32. Zante

    Zante

    Joined:
    Mar 29, 2008
    Posts:
    429
    Hi Yurei,

    Did this happen in UNET as well out of interest? I'm not sure what you mean by "PAUSE". Are you tracking the bullets as physics enabled objects, are there thousands of them?
     
  33. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    769
    It can, and someone already made the adapter.
    Contact Draknith in our discord channel
     
  34. YureiApps

    YureiApps

    Joined:
    Jan 12, 2015
    Posts:
    5
    Hi Zante,
    honestly yes, also with unet I have this kind of pause in packet transmit.
    i'm not tracking the bullets, i'm just spawning from the server in every clients, and then every client just calculate the physics.
    but the problem also happens with the player position. Sometimes the player stop moving on server and after 1-2 seconds start to be tracked again.
    cold be some wrong settings on unity, or maybe some router or firewall settings? i've tried to disable everything but the problem still happens.
     
  35. Loden_Heathen

    Loden_Heathen

    Joined:
    Sep 1, 2012
    Posts:
    480
    Just chiming in here for others like my self that found Mirror on the forums. We where able to integrate Mirror with Steam Networking and once we wrapped our head around it things seemed to go prety smooth. The community on Discord was helpful and pointed us at resources that made it possible. The result thus far (still testing) is better than the previous integration with UNET was as with Mirror we took the approch of swaping out the transport layer as opposed to handling TransportSend on the connection as we did with UNET this gave us better control and an easier time driving this from Steam Lobby
     
  36. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    45
    Oh so uMOBA doesn't use the unity network lobby anymore?? I just checked it out in the store and it looks very Unet??

    I'm sure it was buggy for matchmaking and teams etc but for LAN applications it worked quite well. I think some sort of basic Mirror lobby is essential.
     
  37. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    uMOBA uses a NetworkManagerLobby that inherits from NetworkManager. I made that myself after encountering a new bug in unity's NetworkLobby asset almost every week.
     
    runningbird likes this.
  38. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    204
    If you inherit from a UNET class (NetworkManager), won't that require change when Unity stops shipping UNet?
     
  39. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I'm sure he's using Mirror.NetworkManager rather than UnityEngine.Networking.NetworkManager.
     
  40. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    204
    That makes sense. Thanks.
     
  41. hungrybelome

    hungrybelome

    Joined:
    Dec 31, 2014
    Posts:
    336
    Hi, has anyone tried Mirror/Telepathy with network discovery for mobile server/clients? I used UNET in the past for Android and iOS phones as the host/client, and it worked great. Just wondering if any has tried Mirror/Telepathy for mobile LAN multiplayer.
     
  42. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    We removed the NetworkDiscovery component in Mirror. But you can still do it if you make your own component.
     
  43. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    45
    So upgraded to Mirror...I guess anyone using Dissonance Voip chat is S*** outta luck?? dissonance.png
     
  44. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Looks like it uses some outdated functions from HLAPI still.
    You probably don't want to use VOIP with TCP either. So make sure to set Mirror.Transport.layer to new LLAPITransport or the UDP layer of your choice.
     
  45. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    45
    Oh man:( This S*** is way beyond my pay grade now!!! Can anyone recommend some alternatives that just work out of the box? What about Photon or Forge? Does Unreal Engine have a better solution that works?? Budget is no problem. I'll gladly pay just to have something that works. I'm sure mirror will get there eventually but I don't have time to wait and hope anymore. There HAS to be something out there that can run a simple 4 player LAN game...I mean we are talking 1990's tech here!!!!
     
  46. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Mirror can run a 4 player lan game easily.
    Even hundreds of players are no problem.
     
  47. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    204
    I think this has been asked before, but I can't find an answer on how to implement steps three and four in the install instructions.

    3. Select Runtime/Mirror.Runtime.dll and tell Unity to Exclude the Editor platform
    4. Select Runtime-Editor/Mirror.Runtime.dll and tell Unity to only Include the Editor platform

    Can anyone point me in the right direction? Thanks.
     
  48. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    upload_2018-9-24_22-30-4.png
     
    Strom_CL likes this.
  49. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    204
  50. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    45
    Hey I'm getting these debug logs on instantiated objects. Seems to be working ok but can I check what this 'Huge' problem could be?!!!
    -----------------------------
    AddObserver: connectionId=0 already added for DirtImpact(Clone). Maybe this function was called twice. Or maybe the transport layer generated the same connectionId twice, which would be a huge problem.