Search Unity

Unity Multiplayer Mirror - Networking for Unity (UNET Replacement)

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

  1. lodendsg

    lodendsg

    Joined:
    Sep 1, 2012
    Posts:
    175
    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
     
  2. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    39
    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.
     
  3. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,148
    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.
  4. Ben_Iyan

    Ben_Iyan

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

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    5,494
    I'm sure he's using Mirror.NetworkManager rather than UnityEngine.Networking.NetworkManager.
     
  6. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    174
    That makes sense. Thanks.
     
  7. hungrybelome

    hungrybelome

    Joined:
    Dec 31, 2014
    Posts:
    235
    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.
     
  8. vis2k

    vis2k

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

    Roamer79

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

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,148
    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.
     
  11. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    39
    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!!!!
     
  12. vis2k

    vis2k

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

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    174
    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.
     
  14. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,148
    upload_2018-9-24_22-30-4.png
     
    Striph likes this.
  15. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    174
  16. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    39
    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.
     
  17. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    174
    In the first post, it says:

    If you need the old HLAPI_CE download: 2017.4 Version.

    The title of the download, however, is HLAPI_CE_2017.4_telepathy

    Does anyone know if Telepathy is built in to the dll's, or can we still use UNet's own channels? Thanks.
     
  18. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    39
    I'm getting this warning on every single instantiated object btw...
     
  19. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,148
    Fixed in latest version: https://github.com/vis2k/Mirror/commit/3063273ad4fbb8eb1b4ba88073286420763e6982 . We needed that warning to find a bug a few weeks ago, but not anymore.

    You can set Transport.layer = new LLAPILayer() if you want UNET's low level networking.
     
    Roamer79 likes this.
  20. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    174
    @vis2k Thanks for the response. Would I addd it at the top of the Mirror.NetworkBehaviour? I've been away from HLAPI Pro for quite a while and lots has changed. You've been busy. :)
     
  21. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,148
    You can set it in any of your Awake functions
     
  22. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    677
    In the most recent version of Mirror, override the method InitializeTransport in your NetworkManager and assign it there.
     
    vis2k likes this.
  23. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,148
    News: Mirror is now on the Asset Store! Which means that you can simply download and import it from there, without any extra configurations.

    Enjoy!
     
    Brian-Crandell likes this.
  24. Ceciphar

    Ceciphar

    Joined:
    Jan 21, 2017
    Posts:
    51
    Does mirror work with gamespark and all the other unet plugin?
     
  25. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,148
    Try it, it's free :)
     
  26. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    39
    Will the Asset store be kept up to date with releases as fast as the Github?
     
  27. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    39
    Share your Network Transform sync methods!!!! Ok ppl. Network Transform has always been balls so I know there must be some better custom solutions out there. Does anyone have any transform sync scripts they would like to share?? I have one if anyone wants it. Works well but its not very efficient for traffic. I'd like to see what others are doing to improve. What you got???
     
  28. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,148
    No, asset store uploads and wait time take way too long.
    Will probably upload a new version every week or after major changes.

    I still have one on my hard drive that I will look into again soon. Had a few issues with local player authority, but at least it actually interpolated.
     
    Roamer79 likes this.
  29. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    174
    Thanks, @goldbug. I'm assuming that I still need to call the base method.
     
  30. YureiApps

    YureiApps

    Joined:
    Jan 12, 2015
    Posts:
    5
    I'm having trouble over lan.
    I have a server only that manage bullet prefab and send clients position to other clients.

    I will make an example of what is happening.
    Case: 1 server only, and 1 client.
    the client is sending information about movement(position rotation) and fired bullet (only spawn).

    What happens is that moving the client pc over the room, sometimes (almost every 10/15 seconds), the server stop to receive infomation about the client, and after 2 seconds the server receive all the information all together.

    as example if the clients is moving and shooting, when the server stop to receive info, on server you can't see the client move or shoot, but after teo second the player goes in the right position and ALL the bullets shoot in the past two seconds are spawned all together.

    there is some configuraion i'm missing? or there is some parameter i can tweak? becasue like this isn't possible to use the netwok.
    could be a wireless router problem?

    please help me, this problem is driving me crazy!
     
  31. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,148
    Could be a lot of things.
    Maybe you have a lot of wifi packet loss.
    Maybe you need to call SetDirty in your scripts so that OnSerialize broadcasts new info to other clients sooner.
     
  32. YureiApps

    YureiApps

    Joined:
    Jan 12, 2015
    Posts:
    5
    how can I check if I have packet loss, and why could this be possible?
    the router is dedicated to this network.

    I will try with dirty bit. Do you you think maybe could be a network manager configuration issue?
     
  33. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    39
    You could always try hardwiring your LAN connection and move around to eliminate it being a wifi problem??
     
    vis2k likes this.
  34. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    5,494
    You can just use the ping command as a basic packet loss test

    ping -n 50 192.168.1.1

    Replace that IP address with the IP of the server hosting your game. At the end it will tell you a percentage of packet loss.

    Packet loss is a problem because of how TCP functions. Everything is sent reliable, and a single lost packet will result in the entire stream waiting for the sender to timeout after not receiving an acknowledgement. TCP doesn't send acknowledgement packets for every received packet, instead bundling multiple packets together into a TCP window for a single acknowledgement saying the receiver successfully got all the packets in that TCP window. A single lost packet means the receiver won't be able to send an acknowledgement, has to wait for the sender to timeout waiting for acknowledgement, and the whole window's worth of packets needs to be resent before the receiver will process any later packets.
     
  35. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    677
    No need. This is the base method:

    Code (CSharp):
    1.  
    2. // Initializes the transport,  by default it is Telepathy
    3. // override method if you want to use a different transport
    4. public virtual void InitializeTransport()
    5. {
    6.     Transport.layer = new TelepathyWebsocketsMultiplexTransport();
    7. }
    8.  
    you just override it and assign any transport you want without calling the base method.
     
    vis2k likes this.
  36. YureiApps

    YureiApps

    Joined:
    Jan 12, 2015
    Posts:
    5
    I've tried that and seems that networked the problem isn't there.

    i've tried the ping command to see if there is lost packet.
    i've done the test 10 times with 100 packet every time, and all the test end with no lost packets.
    Here it is the tipical ping results.

    Ping statistics for 192.168.100.10:
    Packets: Sent = 50, Received = 50, Lost = 0 (0% loss),
    Approximate round trip times in milli-seconds:
    Minimum = 1ms, Maximum = 19ms, Average = 1ms


    I think there is something in unity that is giving me problem. i've also tried to create a new blank project, and the problem is still there.
    maybe there is some way to change to unreliable or UDP or someting like that?
     
  37. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,148
    Try the movement demo from the Asset Store ("Mirror"), see if it happens there too
     
  38. lazalong

    lazalong

    Joined:
    Oct 13, 2009
    Posts:
    138
    Hi Viz

    One suggestion and one issue :)

    So that we can track and apply changes present in the GitHub version, could you add the version number of Mirror and Telpathy somewhere in the asset store package?

    The issue are the two errors I get when importing the Asset store version in an empty project with Unity 2018.3.0b2 Personal. However, 2018.2.0b2 does not trigger those errors! Any idea how to fix this for 2018.3+?


    Mirror.Weaver error: Exception :System.IO.IOException: Sharing violation on path Library/ScriptAssemblies/Assembly-CSharp.pdb
    at Mirror.Weaver.Weaver.WeaveAssemblies (System.Collections.Generic.IEnumerable`1[T] assemblies, System.Collections.Generic.IEnumerable`1[T] dependencies, Mono.Cecil.IAssemblyResolver assemblyResolver, System.String outputDir, System.String unityEngineDLLPath, System.String unityUNetDLLPath) [0x0003c] in <ef6d1e9b82304487b0627a9bd2d456ec>:0
    UnityEngine.Debug:LogError(Object)
    Mirror.Weaver.Log:Error(String)
    Mirror.Weaver.Weaver:WeaveAssemblies(IEnumerable`1, IEnumerable`1, IAssemblyResolver, String, String, String)
    Mirror.Weaver.Program:Process(String, String, String, String[], String[], IAssemblyResolver, Action`1, Action`1)
    Mirror.Weaver.<>c:<.cctor>b__0_0(String, CompilerMessage[])
    UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget)




    Weaving failed for: Library/ScriptAssemblies/Assembly-CSharp.dll
    UnityEngine.Debug:LogError(Object)
    Mirror.Weaver.<>c:<.cctor>b__0_0(String, CompilerMessage[])
    UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget)
     
  39. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    677
    A shiny new feature has been added to Mirror today: Time synchronization.

    Starting with Mirror 279, you can get the current time with:
    Code (CSharp):
    1. double now = NetworkTime.time;
    This will give you the same value in the clients and the server. This is useful for latency compensation algorithms such as dead reckoning, targeting, lockstep or simple time delay.

    In addition, you can get the RTT value by calling:
    Code (CSharp):
    1. double rtt = NetworkTime.rtt;
    If you are wondering how accurate this is, you can get the standard deviation for both the time and rtt. Accuracy is measured. In my experiments in local network, time is synchronized with 5ms accuracy.
     
    Last edited: Oct 5, 2018
    vis2k and Roamer79 like this.
  40. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    174
    You're awesome @goldbug thanks :)
     
  41. Ceciphar

    Ceciphar

    Joined:
    Jan 21, 2017
    Posts:
    51
    Does mirror uses unity multiplayer service or p2p or it just uses dedicated servers
     
  42. BryceS

    BryceS

    Joined:
    Jun 10, 2011
    Posts:
    25
    Is there a way to get this working with SSL websocket connections? I couldn't find anything in the API like ConnectionConfig.SSLCertFilePath in UNET.

    Ideally I'd like to be able to use this and host my WebGL game on sites that use https(Kongregate, primarily).

    (Sorry if this has been asked before... the forums won't allow me to search for "SSL" as it's too simple a term :S)
     
  43. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,148
    It doesn't use p2p. Regular server->client model. You can host on dedicated servers yes.
     
  44. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,148
    We still use UNET's LLAPI for websockets, which doesn't support SSL.
    We will try to replace Websockets with another (and open source) solution soon, maybe SSL will be doable then.
     
  45. BryceS

    BryceS

    Joined:
    Jun 10, 2011
    Posts:
    25
    Ahh I see... Thanks for the info!
     
  46. Nyarlathothep

    Nyarlathothep

    Joined:
    Jun 13, 2013
    Posts:
    217
    I'm one of the Dissonance developers, hopefully we can add mirror support. Is there some documentation which lists the differences between the HLAPI (which Dissonance currently uses) and the Mirror API? Hopefully I can just go through that list and make some minor changes to the Dissonance+HLAPI integration to make Dissonance+Mirror work together :)
     
    Dianajmcphee, Jos-Yule and Player7 like this.
  47. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,148
    Mostly use 'using Mirror;' instead of 'using UnityEngine.Networking'.
    Note that Mirror.Transport.layer can be TCP/UDP. And if someone uses TCP then voice chat wouldn't be the smartest idea.
    It might make sense for the chat to work independently of Mirror, or show a warning if someone doesn't use the UDP backend in Mirror while using your voice chat.
    The UDP backend is Mirror.Transport.layer = new LLAPITransport();
     
    Nyarlathothep likes this.
  48. Nyarlathothep

    Nyarlathothep

    Joined:
    Jun 13, 2013
    Posts:
    217
    Aha ok, I don't know if @Roamer79 (who requested Mirror support) tried that.

    Since UNet is going to be deprecated soon what are the long term plans for unreliable backends for Mirror? Obviously there's no point in us adding mirror support if it's not going to have unreliable network transport in the long term!

    That's already possible, we've got several other network backends which could run side-by-side with mirror (e.g. use WebRTC network to run a P2P voice session alongside the gameplay) :)
     
  49. Roamer79

    Roamer79

    Joined:
    Oct 25, 2016
    Posts:
    39

    So I have managed to get Dissonance working on Mirror using the LLAPI standalone version of dissonance however it is running on TCP reliable which is not so great as Vis2k points out. Occasionally you get "out of resources errors".

    The problem is I want TCP reliable for my game as it works so well. Now all we need is an unreliable channel to dedicate to Voip.

    Mirror only allows you to pick one or the other 'globally' and we really need the option of both.

    One option which would be great for Dissonance flexibility regardless of networking choice would be to mod the standalone version to use its own custom server and not base it on unity networking engine at all??
     
    Nyarlathothep likes this.
  50. Nyarlathothep

    Nyarlathothep

    Joined:
    Jun 13, 2013
    Posts:
    217
    Dissonance pretty much already does that, you can use any networking backend you like. So as I mentioned above you could try using the WebRTC Network integration for Dissonance to host a totally p2p voice session alongside your game session. You could maybe also use the LLAPI integration for Dissonance which hosts it's own LLAPI network session, rather than relying on using your game session - so you can use Mirror with reliable networking for your game and just use LLAPI for voice.