Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    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. Enignum

    Enignum

    Joined:
    Feb 28, 2017
    Posts:
    7
    Hi,
    I'm thinking of example: 50 players in a game, 50 rigidbodies...
    Do I have to try some sort of optimizing or just slap NetworkTransform to the Rigidbodies and it should be fine? Or will it be too much for the server/connection/lag?

    What about "Smooth Sync" from the Asset Store? Does it have sense or is Mirror already optimized enough in this case?

    Thanks! ;)
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    9,580
    How often you need to sync things, and how much data you need to sync, will dramatically affect how well that kind of set up works for you. For example, just with transform updates if you need to update all 50 rigidbodies to all 50 clients at 29 times per second that will be a significant number of messages compared to updating at a lower rate (say 5 times per second) only to nearby clients. You'll undoubtedly have other data as well you will want to update on a regular basis.
     
  3. Enignum

    Enignum

    Joined:
    Feb 28, 2017
    Posts:
    7
    Let's say it's some sort of Golf game and rigidbodies can collide with each other... So frequent updates for smooth gameplay and most of the time most players will see them :(
     
  4. Johan_Valectric

    Johan_Valectric

    Joined:
    Nov 28, 2019
    Posts:
    11
    I'm looking for a freelancer who has done some work using Mirror? I'm searching on Fiverr but it takes time to find a good one so any tips is most appreciated. You can shoot me a PM or an Email at johan.holtby@valectric.se so we don't hog this thread. Also tips on where to post other than here is appreciated. :)
     
  5. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,715
    Feel free to ask in our Mirror discord (see my signature)
     
    Johan_Valectric likes this.
  6. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,434
    Hi, I'm currently integrating the great Mirror (thanks!!) for the first time into an existing game, and I have a question that I feel is so stupid that nobody has asked it or already knows the answer to. I googled this first (I don't want to waste your time), but came up empty.

    Here's the setup:
    The game uses a Lobby built on Unity's own 'Lobby' asset.As such, it 'using UnityEngine.Networking.Match' and some others (e.g.*.Types). I noticed that following your Transition guide, the global replacement will leave these untouched, merely exchanging the UnityEngine.Networking for Mirror.

    Stoopid Questions:
    1. Should I leave these 'using' clauses referring UnityEngine.Networking in place, or are there Mirror equivalents? Currently, there is no Mirror.Match nor Mirror.Types
    2. One of the reasons I'm migrating to Mirror (besides better code quality in Mirror :) ) is that i want to go to 2019 which removed UNet. Will those using clauses (.Match and .Types) still work there?
    3. The Lobby demo from Unity never really worked well (requiring re re-start of the game after finishing a network game, returning to the lobby always returned network errors that prevented another connection). Do you have a recommendation for a better working lobby system? Ripping the lobby out will hurt, but I've lost so much hair over that lobby that I'm open to suggestions.
    Thanks for any suggestions, and for a great asset!

    -ch
     
    Last edited: Dec 16, 2019
    D3m0n likes this.
  7. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    335
    What was called Lobby in UNet was renamed to Room system in Mirror, and the bugs were fixed and it does work. A new example is included with Mirror for that.

    There is however no Match service integration since Unity will be taking that down.

    For faster response, please join our Discord.

    Thanks!
     
    csofranz likes this.
  8. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,434
    Thanks!

    Since that game is sold via steam, I'll see if I can use Steam's matchmaking instead (more precisely: the P2P networking, which hopefully also will allow us to stop throwing money at Unity's deteriorating server infrastructure).

    -ch
     
  9. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,715
    We already have a steam transport for Mirror. Check out our discord!
     
    csofranz and Joe-Censored like this.
  10. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,715
    Progress: we fixed a race condition in the NetworkManager's StartHost function. Next version will be pushed to Asset Store asap.

    Working on further improvements as usual. Join our discord if you have any questions.
     
    Refeas likes this.
  11. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,434
    There is a long-standing bug ('feature?) in UNet's Network Manager that I've run into, and which seems to be implemented in Mirror as well (so it's fully bug-compatible :)):
    To make it easier to understand, let's imagine we implement an MP game where one player is Host, the other Client, and all games are single-scene short affairs that last a few minutes each, so clients routinely connect and dsconnect from Hosts.

    Now regard this sequence:
    • a game starts in client mode, and successfully connects to the host
    • and a few minutes later the game then ends. Client disconnects and returns (via offline scene) to, uh, the offline scene
    • A new game is set up, and the Host starts a new game. If in the Client's NetworkManager the 'online scene' attribute is not set (i.e. it is a blank/empty string), the Network Manager will not load the scene the Host specifies, but immeadiately signat to the Host that it is ready. This prompts the Host to tell the Client to start loading Assets (usually at least the player prefab) that do not exist (the Client is still in the offline scene)
    • This results in a non-recoverable situation.
    Obviously, the remedy is to never leave the onlineScene attribute blank, but you will only program for this if you know about this bug. If you don't, you seem to have an intermittend error on your hands, that might cost you all your remaining hair. I recommend you modify the NM so that it outputs a warning when starting the Client on an empty onlineScene attribute

    Oh, and again thanks for a great resource!

    -ch
     
  12. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,715
    Please post it on our github issue tracker :)
     
  13. Privateer

    Privateer

    Joined:
    Jun 5, 2016
    Posts:
    21
    How would you go about it?
     
    QQuixotic likes this.
  14. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,715
    Privateer likes this.
  15. bystrickdm

    bystrickdm

    Joined:
    Jan 9, 2020
    Posts:
    1
    Hello! I am your sponsor on GitHub. I really like Mirror PRO. But I can’t work with them, because Link to Download Mirror PRO does not work. What should I do?
     
  16. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,715
    News: fixed all open bugs this week:
    upload_2020-1-10_16-21-14.png
    Enjoy!


    Contact us in discord please.
     
    D3m0n and hopeful like this.
  17. digiross

    digiross

    Joined:
    Jun 29, 2012
    Posts:
    268
    Ok after a lot of research on the various networking threads I'm convinced that Mirror is the way to go for my game. I'm not new to game dev just multiplayer and i'm starting a 3rd person shooter and I'm wanting to build the game from the ground up with multiplayer included (as recommended).

    Previously, I was considering Photon but appears to be limiting with it's message limits but it does have relays globally.

    Anyways, using Mirror I know I would set up a server but what is recommended to have global low ping without me hosting a bunch of different places. Any choices besides Amaon AWS?

    Thanks in advance.
     
    Last edited: Jan 14, 2020
    vis2k likes this.
  18. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,715
    A relay is just a separate service.
    We might host a relay ourselves some day. But that wouldn't require any Mirror modifications.

    In other words: you can use any existing relay from the internet, or code your own, or wait until we do :)
    Or just host servers yourself.
     
  19. BitPax

    BitPax

    Joined:
    Oct 4, 2019
    Posts:
    46
    Is there a tutorial for setting a Mirror server up on a VPS (Virtual Private Server) like Digital Ocean?
     
  20. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,715
    Yes, check out our documentation
     
  21. BitPax

    BitPax

    Joined:
    Oct 4, 2019
    Posts:
    46
    I must be confused. I looked at the documentation but I couldn't find a tutorial for setting it up on a VPS. Could you help me out with a link?
     
  22. bigd53618

    bigd53618

    Joined:
    Sep 23, 2017
    Posts:
    18
    How do you make sure old cameras our local players and not controlling other characters
     
  23. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,715
  24. Togias

    Togias

    Joined:
    Jul 17, 2017
    Posts:
    6
    Hallo, I am having an issue or maybe i am not configuring the scene right.
    I setup my server in a different scene than the client scene.
    I build the server and run it.
    Every time the client connects to the server i get


    Could not spawn assetId=00000000-0000-0000-0000-000000000000 scene=5773007113619659104 netId=2
    UnityEngine.Debug:LogError(Object)
    Mirror.ClientScene:OnSpawn(SpawnMessage) (at Assets/Mirror/Runtime/ClientScene.cs:526)
    Mirror.<>c__DisplayClass36_0`1:<RegisterHandler>b__0(NetworkConnection, SpawnMessage) (at Assets/Mirror/Runtime/NetworkClient.cs:421)
    Mirror.<>c__DisplayClass7_0`1:<MessageHandler>b__0(NetworkMessage) (at Assets/Mirror/Runtime/MessagePacker.cs:169)
    Mirror.NetworkConnection:InvokeHandler(Int32, NetworkReader, Int32) (at Assets/Mirror/Runtime/NetworkConnection.cs:301)
    Mirror.NetworkConnection:TransportReceive(ArraySegment`1, Int32) (at Assets/Mirror/Runtime/NetworkConnection.cs:357)
    Mirror.NetworkClient:OnDataReceived(ArraySegment`1, Int32) (at Assets/Mirror/Runtime/NetworkClient.cs:168)
    UnityEngine.Events.UnityEvent`2:Invoke(ArraySegment`1, Int32)
    Mirror.TelepathyTransport:processClientMessage() (at Assets/Mirror/Runtime/Transport/TelepathyTransport.cs:92)
    Mirror.TelepathyTransport:LateUpdate() (at Assets/Mirror/Runtime/Transport/TelepathyTransport.cs:119)
     
  25. katasteel

    katasteel

    Joined:
    Nov 21, 2014
    Posts:
    233
    I noticed when I send a message from a object with client authority like this:
    Code (CSharp):
    1. NetworkClient.Send(new UMAManangerSync());
    The netId of object sending it is 5. The netId of of the object that spawned the object is 1.

    When the server gets the message it has the netId of the player that spawned it and not the id of the object that sent it.
    Code (CSharp):
    1. public void OnSyncFromClientToServer(NetworkConnection connection, UMAManangerSync message)
    2. {
    3.     if (netId == connection.identity.netId)
    4.     {
    5.         //to do
    6.     }
    7. }
    When the method is called it never gets inside because the netId is 5 but the connection.identity.netId is 1. This used to work fine under UNET.
     
    Last edited: Feb 9, 2020
  26. JWLewis777

    JWLewis777

    Joined:
    May 17, 2015
    Posts:
    86
    Hello!
    Looking to really dive into Mirror and give it a go. Ultimately looking to create a peer 2 peer networking system. There are a few things I've already stumbled on and looking to get some more information on.

    I was looking to create the most basic Server-Host-Client system possible on a local machine, but when following the guide from here...https://mirror-networking.com/docs/Guides/ClientsServers.html
    The SetupLocalClient() method doesnt do anything. I was thinking that it would need to start a listen server in order for clients to join, while also being a client itself but the method as written in the guide just creates the Message handler, it doesn't start the server or client.

    I will also be looking at changing the Transport down the road to the litenetlib in order to utilize the Nat Punchthrough (Hopefully), but I can't seem to find any information on doing this.

    Thanks for any help!
    :)
     
  27. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,715
    Try one of our built in examples, like Tanks. it works out of the box :)
     
  28. JWLewis777

    JWLewis777

    Joined:
    May 17, 2015
    Posts:
    86
    Thanks for the reply,
    I dont really see how looking at a more involved, more intricate example would help understand why the docs example isn't working as expected, especially since the docs example is as basic as it can get.

    The Tanks and Pong use the Network Manager Hud to handle connections and this happens behind the scenes. I wanted more control of this so I could understand it better.

    This is why I was trying to start from the very basic, most simple way of doing a client server setup. The docs guide looked perfect, but things aren't working as expected, like when I click setup server and then run setup client in a different window, when the client is connecting instead of getting the Debug.Log("Connected to server") from the OnConnected message handler, I get an unknown message ID 55829 connection(1).

    So it seems the docs clientserver example isn't working correctly.
     
  29. magickprogramando

    magickprogramando

    Joined:
    Mar 8, 2017
    Posts:
    24
    Hi!What happens if someone has closed ports? Is there a way around this without having to ask each person to open the ports?
     
  30. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,715
    Host your server on the internet. For example, google cloud offers a free f1-micro instance that you can try.
     
  31. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,715
    Mirror Progress Update:
    We are working on bug fixes and hardening / tests.
    Right now, we are at 42.3% test coverage.
    We will remove all obsolete code in a month or two, then we will see the true test coverage. It should be around 50%.
    50% isn't perfect, but we are getting there!
    upload_2020-2-23_14-30-44.png

    To put this in context: we want to cover as much code as possible with tests for maximum reliability. The closer we get to 100%, the less likely it is that someone encounters a Mirror bug.

    Think about it this way: with 0% code coverage, anything could go wrong in production. With 100% coverage, you can be confident that your game's networking is not gonna fail.

    It also helps us to improve old code more. Every time we change something, we can run our tests to make sure that we didn't break anything unexpectedly.

    When someone reports a bug, we can add a test case for it so that the bug never happens again in the future.

    This is going to be the biggest Mirror feature of 2020. It won't look exciting, but it will be extremely useful for everyone that uses Mirror for their games. We can't allow it to fail when you run an MMO with 1k online players. It's just not an option.
     
    Last edited: Feb 23, 2020
    jjobby, iSleepzZz and AlexHolderDev like this.
  32. Davood_Kharmanzar

    Davood_Kharmanzar

    Joined:
    Sep 20, 2017
    Posts:
    388
    does exists any manual to how to build headless server with MiRRoR?
    and howto run server with specific commands? i mean call server with specific commands to load specific map or scene with their parameters and etc ..
     
  33. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    9,580
    You can pass your Unity build any command line argument you want. From an older thread:
    Then you'd just check for certain arguments in the returned array and act on them. This isn't really a Mirror specific thing, or even networking related. You could do this kind of thing in the client if you wanted a way for players to force certain options in your game without editing a config file or getting into an options menu.

    As for headless, that's again unrelated to Mirror or networking. You just use -batchmode -nographics which are built in command line arguments for Unity builds. For platforms like Linux which have the headless build check box, check that as well so it doesn't even include graphics related stuff in the build in the first place.
    https://docs.unity3d.com/Manual/CommandLineArguments.html
     
  34. zhn17

    zhn17

    Joined:
    Jul 30, 2019
    Posts:
    49
    Been searching for a response to this question but found none
    How would I go by syncing a animation "manually" via Object.Anim.Play("Run", 0);?
    I've got everything set up for a multiplayer game using Malbers' HorseAnimset PRO asset, all animations except some, mounting being one of those.
     
  35. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,434
    I would make it a server command that is issued by the player with authority, and then passed to all clients via rpc
     
  36. zhn17

    zhn17

    Joined:
    Jul 30, 2019
    Posts:
    49
    Could you write how to do it?
    I've done stuff with Commands and RPC before but never with Authority
     
  37. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,434
    Luckily, this isn't that difficult. First, make sure that the script that needs to sync the animation is a networked object (has a Network id). This means that the script that wants to set the animation runs on all Clients, and must make sure that it is part of the object that can make such decisions (i.e. has authority), not one that is merely a clone. You do that by checking the hasAuthority bool.

    To make sure that the Animation is set on all clients, the script then sends a command (that you define yourself) to the server. Only scripts with authority can do that. On the server, the command is executed and it calls the Client remote procedure to actually set the Animation, passing along the relevant Parameters.

    the logic should be similar (i'm typing this off the top of my head, I'm on the road) to this

    Code (CSharp):
    1. ... // in the networked script
    2. if (hasAuthority) {
    3.    CmdSetAnim("Run", 0);
    4. }
    5.  
    6. ...
    7.  
    8. // server-only part
    9. [Command] public void CmdSetAnim(string Name, int id){
    10.    // call the Clients and have them set anim
    11.    RpcSetAnim(Name, id);
    12. }
    13.  
    14. // Client part, executed on all Clients
    15. [ClientRpc] public void RpcSetAnim(string Name, int id) {
    16.    Object.Anim.Play(Name, id);
    17. }
    18.  
    Note that you must insure that all scripts have correctly linked to the same instance of "Object", further Network logic for that may be required.
     
    vis2k and zhn17 like this.
  38. zhn17

    zhn17

    Joined:
    Jul 30, 2019
    Posts:
    49
    Alright, thanks. I'll update you with the progress if I get it working, considering Malbers' horse animset pro is really badly coded
     
  39. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,715
    Progress Update: we went from 0 to 29 NetworkServer tests, which helped us discover and fix 5 bugs:
    upload_2020-2-26_18-39-17.png

    That's 5 bugs that your players won't encounter in production :)
     
    Matt-Cranktrain, yploid and Griz like this.
  40. zhn17

    zhn17

    Joined:
    Jul 30, 2019
    Posts:
    49
    Seems to work for the mounting and dismounting (haven't had time to do it for the horse yet), thanks for the help!
     
  41. xerokwan

    xerokwan

    Joined:
    Jun 23, 2017
    Posts:
    4
    I want to adopt my game to addressables recently, it seems there are a lot of work to do to switch SceneManager.LoadSceneAsync to Addressables.LoadSceneAsync in NetworkManager because they are using different return types and handlers...Anyone got any idea to do it much more cleaner and simpler instead of altering hundreds lines of codes?
     
    AlexHolderDev likes this.
  42. KAYUMIY

    KAYUMIY

    Joined:
    Nov 12, 2015
    Posts:
    115
    How to install mobile / desktop communication with wifi?
    I am testing Chat scene but I fail.
    Is there any documentation or tutorial how to make comunnimcation environement?
     
  43. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,715
    Try to host the chat server on a vps/dedicated/cloud server on the internet.
     
    KAYUMIY likes this.
  44. KAYUMIY

    KAYUMIY

    Joined:
    Nov 12, 2015
    Posts:
    115
    I don't know how to move chat server to cloud.
    Can you explain it in detail please?
    How to host chat server on the cloud server on the internet?
     
  45. zhn17

    zhn17

    Joined:
    Jul 30, 2019
    Posts:
    49
    A quick Google search explains how to get a server.
     
    KAYUMIY likes this.
  46. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,715
    Mirror Progress Update:
    We have the single most complex UNET function now fully covered in tests:


    This allows us to modify and improve it, hopefully with some performance gains in observer building (which is still an easy bottleneck to encounter).

    The rest of NetworkIdentity is almost entirely covered by tests now too:
    https://gyazo.com/787f3150b6873beb7f4ce2002a5801e3
    The red parts are mostly obsoletes that will be removed in 1-2 months. This is HUGE for stability in every single Mirror project for the next 5-10 years!
     
    Matt-Cranktrain and KAYUMIY like this.
  47. KAYUMIY

    KAYUMIY

    Joined:
    Nov 12, 2015
    Posts:
    115
    Do you think Google Cloud plafrom can be solution for the desktop & mobile communication project?
     
  48. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,715
    Yes, we use it for our list server and demo projects too.
     
    KAYUMIY likes this.
  49. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,715
    Mirror Progress Update: NetworkBehaviourTests finished with 96.1% code coverage. More after we remove obsoletes.

    In other words, it's extremely unlikely that NetworkBehaviour will have bugs ever again.
    upload_2020-3-7_20-54-43.png
     
  50. itzikpel

    itzikpel

    Joined:
    Mar 27, 2015
    Posts:
    16
    Hi,
    I have two questions

    #1: Can I have nested NetworkIdentity of different clients?
    example:
    A non VR player is driving the Bus and a VR Player can walk inside the Bus.
    If I set the VR player position/rotation offset to the bus - the movement is very laggy..
    If the VR player is the child of the Bus - its works perfect..

    #2: Can I have nested NetworkIdentity of the same client?
    example:
    A player charcater is walking in the street
    Each car in the street have a NetworkIdentity without client authority
    When the player start to drive, I'm parenting the player character to the car GameObject -
    And set the client authority of the car to be the same as the player,
    When the player stop driving, I'm unparenting the character from the car and release the client authority from the car

    thanks
     
    Last edited: Mar 11, 2020
    tylerguitar75 likes this.
unityunity