Search Unity

  1. We have added dedicated sub-forums for UNet, the experimental MLAPI and Unity Transport Package. Please use the new forums to discuss related topics.
    Dismiss Notice
  2. How can our website serve you better? Give us your feedback. Take our survey and let us know.
    Dismiss Notice

Unity Multiplayer Mirror - Open Source Networking for Unity

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

  1. tenukii

    tenukii

    Joined:
    Mar 31, 2014
    Posts:
    4
    vis2k likes this.
  2. shawnblais

    shawnblais

    Joined:
    Oct 11, 2012
    Posts:
    322
    Sorry if this is answered in the docs, I couldn't find anything specifically talking about size limits, or where to store large amounts shared data.

    We're considering using Mirror for a Valheim-style game, it would be procedurally generated, and have a very large list of world modifications and items that all players would need to share, the owner of the world would provide the seed, and the list of world modifications, anyone else can write back to that list while the game is running.

    Is this doable with mirror? Would we just use a hash-table to share all the info amongst players?
     
  3. dario17231

    dario17231

    Joined:
    Nov 21, 2020
    Posts:
    1
    Did you find a solution for this error? Which transport are you using?
     
  4. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,929
    Most transports have a configurable max message size.
    Default kcp transport max message size is around 140 KB.
    Other transports like Telepathy can have up to 2GB (although that might not be a good idea).
     
  5. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,929
    Yes, this was an android mono bug.
    You need to upgrade to latest Mirror on github :)
     
  6. funkyjive

    funkyjive

    Joined:
    Jan 11, 2013
    Posts:
    2
    I'm wondering if I'm missing something obvious here so let me make a few statements and see what I am doing wrong with my setup.

    Context: Networked game where the players are relatively slow moving balloon objects that can bump into each other as physics entities. Because the movements are relatively slow I am ok with all physics taking place on the server and clients have smooth positions and rotations albeit slightly delayed from the physics happening on the server. The gameplay is slow enough I think that would work but the key item is that the movement needs to be smooth since this is VR and if the rig jitters motion sickness happens. I'm willing to trade latency and client side accuracy for smoothness.

    So the player object has a rigidbody and some colliders.

    Here's what I've tried and observed:

    Config 1) Simple network transform on the prefab, sync interval set to 1. Client has occasional "hiccups" where rotation and position isn't exactly smooth. Almost tolerable. I'm guessing the rigidbody on the client still being active is fighting with the network transform?

    Config 2) Same as config 1 but sync interval set to 0. Much choppier than config 1. I assume sync interval 0 means only send transform updates when the sensitivity threshold value is hit?

    Config 3) Same as config 1 and 2 but sync interval set to 0.01. Much choppier than config 1. Still seeing hiccups and jitter.

    Config 4) Network Lerp rigidbody. Rotations don't seem to be happening from server -> client. Position and velocity looks smooth but no rotations.




    Question 1) Does network transform do any interpolation? If so then I must be seeing the effects of the rigidbody still being active on the client causing stuttering.

    Question 2) Is there a reason lerp rigidbody does position and velocity but not angular velocity or rotation? I don't think this is the right solution for my use case of wanting the physics to only run on the server but it was something I tried anyways.

    Question 3) One config I did not try is the simple network transform but having some script client-side disable its rigidbody. As I type this out it seems obvious that leaving the rigidbody component enabled on a client seems like it would only screw up the client side movement. I'll be trying that next. It looks like there is no "enable" for rigidbodies like some other components. There must be some other way around that.
     
  7. unfocused-locust

    unfocused-locust

    Joined:
    Mar 22, 2020
    Posts:
    6
    Sorry if this is obvious, first time networking with Unity.

    I've been tinkering for a few days now with a simple turn-based, text-based game, and I've got all the specifics figured out. The only problem is that whenever I join a game as a client, it disconnects and boots me to the offline scene every time the player sends a command. This doesn't happen with a server or host connection, just the standalone client. It happens in the editor and build, with KCP or Websocket transports. I've searched just about every search term there is to search, and I can provide more details if need be. Please send help :')

    (I call the command in Update, which executes up until the command, then I get an error that whatever transport I am using got sent a "disconnect" tick.)
     
  8. BenniKo

    BenniKo

    Joined:
    Mar 24, 2015
    Posts:
    97
    If you call it in update, do you make sure it gets called only once or are you calling it repeatedly from update?
     
  9. unfocused-locust

    unfocused-locust

    Joined:
    Mar 22, 2020
    Posts:
    6
    After some tests, it looks like it happens even if I don't call the command. My first command to add the player to the "all players" list (stored in a subclass of NetworkManager) appears to execute, but does not register server-side (the command executes in OnStartLocalPlayer). Update executes once (there are no commands called in Update), and then the client disconnects before Update can be called for the second frame.
     
  10. BenniKo

    BenniKo

    Joined:
    Mar 24, 2015
    Posts:
    97
    It's difficult to help you without seeing the actual code. I was just guessing that your command triggers too often from update. Since it doesn't I am out of ideas.
     
  11. unfocused-locust

    unfocused-locust

    Joined:
    Mar 22, 2020
    Posts:
    6
    Never mind! I just refactored my code after looking through some more docs. Thanks for the help, though. :D
     
  12. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,929
    Hey guys. Friendly reminder that we have Mirror Discord community with >10,000 people.
    https://discord.gg/N9QVxbM
    I usually don't have much time to reply on the forums, and MrGadget is only active in Discord :)
     
  13. alicivril

    alicivril

    Joined:
    Nov 3, 2020
    Posts:
    2
    Hi everyone,
    I have chosen Mirror for its simplicity and power for the development of a multiplayer game. One single and simple question, that I would really like to see answered: In the Network Manager component, Network Info->Transport field, I cannot see any options other than KCP. My version is 35 something, just downloaded yesterday. Any problem with this? Or, the others are not supported anymore?

    Best
     
    vis2k likes this.
  14. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,929
    Check out our Discord / Github page to find different transports.
    But kcp is fine :)
     
  15. alicivril

    alicivril

    Joined:
    Nov 3, 2020
    Posts:
    2
    Thanks for getting back with an answer so quick. Two more concerns/questions though: By saying kcp is fine, do you mean it is as good as to handle an action game like UDP? Second one: With KCP, can I do port forwarding on my router so that someone else can connect to my server? It seems like I can only do it with TCP or UDP from my router settings, no KCP option.
     
  16. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,929
    KCP is a reliability algorithm. It goes over UDP. So you have to open UDP ports.
    FakeByte made a free relay for Mirror btw. Uses Epic online services. So you don't need to open ports anymore :)
     
    alicivril likes this.
  17. preynolds0521

    preynolds0521

    Joined:
    Mar 25, 2021
    Posts:
    3
    Is there a reason that an android device hosting on local wifi would not be found by another device on the same wifi trying to connect as a client? I've been searching for a while and can't find anything on android-to-android communication. I start my game up and start it as a host, which seems to work fine, but when I start it on my other phone and try to join at the same IP it tries to connect, then disconnects after a few seconds.

    Thanks!
     
  18. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,929
    Local network connections are difficult sometimes.
    If you've ever been on a LAN party then you still remember that :)
     
  19. Kamzoki

    Kamzoki

    Joined:
    Apr 25, 2016
    Posts:
    8
    In the docs, NetworkServer, as well as MsgType, are marked as deprecated, but I'm following this example to connect Playfab to Mirror.

    I checked the docs for alternative methods but couldn't find any. What should I use to replace NetworkServer and MsgType?
     
  20. BenniKo

    BenniKo

    Joined:
    Mar 24, 2015
    Posts:
    97
  21. Kamzoki

    Kamzoki

    Joined:
    Apr 25, 2016
    Posts:
    8
    I was looking at the correct docs though. Let me tell you exactly what I need to understand.

    I'm building a server using Unity/Playfab/Mirror. In my ServerStartUp script, I want to check the OnServerConnect so that I may invoke other functionalities. Problem is, Mirror's OnServerConnect doesn't get called when an actual user connects to playfab server. So I have to handle this manually somehow. I thought about using NetworkServer.RegisterHandler(MsgType.Connect, OnServerConnect) But this is Deprecated UNET and I can't seem to find a replacement for that.

    I ultimately just want to tell mirror to use a remote server instead of hosting games on my PC.
     
    Last edited: Apr 18, 2021
  22. BenniKo

    BenniKo

    Joined:
    Mar 24, 2015
    Posts:
    97
    I am using playfab too and I am pretty sure OnServerConnect works.
    I wrote a guide to setup playfab, maybe that will help you.
    It is not about mirror though, it is just about setting up playfab and unity just before you would add communication via mirror.
    https://jarc.xida.net/2021/04/06/playfab-multiplayer/
     
  23. Kamzoki

    Kamzoki

    Joined:
    Apr 25, 2016
    Posts:
    8
    Thanks a ton. I'll take a look at your guide.
     
  24. Kamzoki

    Kamzoki

    Joined:
    Apr 25, 2016
    Posts:
    8
    So I got it to work thanks to your guide. But here's where I'm stuck, again. I'm using Playfab matchmaking, I successfully matched two players and on match found I do this:

    Code (CSharp):
    1. private void OnGetMatch(GetMatchResult result)
    2.     {
    3.         UpdateStatusText($"{ result.Members[0].Entity.Id} vs { result.Members[1].Entity.Id}");
    4.        
    5.         //configure mirror network
    6.         NetworkManager.singleton.networkAddress = result.ServerDetails.IPV4Address;
    7.         NetworkManager.singleton.gameObject.GetComponent<KcpTransport>().Port = (ushort)result.ServerDetails.Ports[0].Num;
    8.  
    9.         NetworkManager.singleton.maxConnections = playerData.SelectedMap.MaxPlayers;
    10.         NetworkManager.singleton.onlineScene = playerData.SelectedMap.MapName;
    11.  
    12.         //start client
    13.         NetworkManager.singleton.StartClient();
    14.     }
    But nothing happens, the client just starts and shuts down. Should I make one of the players a host? and how would I go about doing this?
     
  25. BenniKo

    BenniKo

    Joined:
    Mar 24, 2015
    Posts:
    97
    Sorry, I didn't use playfab's matchmaking yet.
    But as a general tip:
    You can connect to the playfab server via remote desktop. Then you can check the logs of your unity server to find out what is going on.
     
    Kamzoki likes this.
  26. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,929
    I think someone made a playfab Mirror plugin already, check our discord.
    Wasn't it Microsoft even?
     
  27. Kamzoki

    Kamzoki

    Joined:
    Apr 25, 2016
    Posts:
    8
    I only found the playmaker playfab package.

    Okay, here's another question that might help me. In mirror's NetworkManager.cs, there's a function called StartHost. If I called this function on the server build on play fab, then called StartClient on each client as they start the match, will this be equivalent to what we do locally via the network hud? (Start host, join client)
     
  28. BenniKo

    BenniKo

    Joined:
    Mar 24, 2015
    Posts:
    97
    Playfab works exactly as you would work locally.
    On Playfab there is a virtual windows or linux pc running with your server that you build from within unity.
    So yes everything on playfab works just as you would work locally.
    As I mentioned earlier you can even use remote desktop to connect to the current running server on playfab and check for any problems.

    If you use the network hud:
    You need to insert a ip and port into the hud.
    Which means yes, this will work the same for playfab.
    As soon as you got a running server on playfab and know the server's port and ip you can enter that into the hud.

    By the way: The best way to test locally is to open two unity instances at the same time.
    And to do this I highly recommend https://forum.unity.com/threads/edi...er-without-building-uecho-replacement.964388/
     
  29. Kamzoki

    Kamzoki

    Joined:
    Apr 25, 2016
    Posts:
    8
    Thanks a lot for the comprehensive response. I'll fiddle with it more now that I understand that playfab's environment is the same as my local pc.
     
  30. KarimGameil

    KarimGameil

    Joined:
    Jan 21, 2021
    Posts:
    1
    Hi guys, I have a weird problem.

    When I host the game on editor and join as a separate client on the same machine the host client moves normally but the other client moves VERY fast.

    and when I host from the build and login with client through the editor, the build host moves normally while the other one on the editor moves VERY slowly.. please help
     
  31. AlphaBlazer

    AlphaBlazer

    Joined:
    Sep 2, 2019
    Posts:
    9
    I have the camera for the player as a child of the player object. If the player object has a network identity component on it, the child camera stops rendering. The network identity is not set to server only. Is there a way to render the camera while it is still the child of an object with a network identity?
     
  32. boomerang4

    boomerang4

    Joined:
    Jan 4, 2018
    Posts:
    5
    Mirror, or mirror-users please help:

    Where is the proper/best place to call a loading screen from? Or, how do you pass info to clients during async scene load?

    I can get it working for the server just fine, but when it comes to communicating things like loading progress to clients it seems like there's a black hole that swallows hooks/syncvars and ClientRPCs during async scene load (no errors or anything, the functions calling the RPCs go through but the actual RPCs themselves just never happen). I'm trying to get around syncvars/RPC by using OnClient/ServerChangedScene and the like, but it feels very hacky and again the whole "progress" part just jumps from 0 to 100 for clients so kind of defeats the purpose. Been at this for hours! Help!
     
  33. jhbyhuangzejie

    jhbyhuangzejie

    Joined:
    Mar 10, 2017
    Posts:
    7
    I want to realize the hall function how to achieve, and what good plan?thank you
     
  34. Programmingat23505

    Programmingat23505

    Joined:
    Sep 15, 2020
    Posts:
    38
    I have integrated vivox communications with my game and the logon credentials are stored in a variable set in the inspector, if on start I set a sync var to the same set of strings will it update when I start the server? Or do I need to set them when the is actually started?
     
    Last edited: May 15, 2021
  35. jamesjenningsard

    jamesjenningsard

    Joined:
    Jun 26, 2020
    Posts:
    6
    Hi friends

    I have a fun little "remote control audio player" working pretty swell, thanks to Mirror. I have FMOD running the audio, triggered by a pretty basic [Command]/[ClientRPC] loop-around.

    On iOS, my FMOD continues to play after locking the screen, and the Mirror Client (from a distance, it seems like) is continuing to receive, and queue incoming ClientRPC's. Then processing them all, simultaneously, when the app resumes focus.

    That what it seems like is happening, anyway.

    Question: I'm curious if there's any trick to getting those commands to process when the screen is off. I know iOS is very picky about what gets processed in the background, so my hopes are modest, but I'm curious if there's any sort of method worth trying? Perhaps in conjunction with the mobile task invoker?

    I'm sure I'm just misunderstanding what's possible, but I figured I would check in to see if anyone had any insight.
     
  36. no00ob

    no00ob

    Joined:
    Dec 13, 2017
    Posts:
    60
    I know this seems like an odd problem but why is Mirror adding a NetworkIdentity component to one of my scene objects in a scene with no network managers or other mirror components present? It's very annoying when I'm trying to playtest my game and this one object keeps disappearing and I have to manually enable it.
     
  37. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,929
    We can't see your screen from here, would need more details :)
     
  38. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,929
    New Mirror GitHub is live.
    2021-05-21 - github page with dreamers_white.png
     
    VirtualPierogi, Ruchir and BenniKo like this.
  39. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,929
    jesusluvsyooh and Ruchir like this.
  40. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,929
    Great news: we achieved a 25x reduction in Socket.ReceiveFrom/SendTo allocations with
    where-allocation

    Below is our Benchmark example, sending 1000 monsters to 1 connection via KCP.
    8.9 KB per flush before.
    364 B after.

    We might be able to reduce it to 0 B with Unity 2021.0.2a19, which is supposed to be released this week.

    No more native C DLL workarounds to avoid allocations :)
     
  41. BBernard

    BBernard

    Joined:
    Jun 3, 2021
    Posts:
    1
    Hi and WOW! Tell me, please, can we use this info in the 2nd part of our article? We'd like to dedicate it to unity and unity vulnerabilities. Thanks in advance, Brit
     
  42. FellowPlayer123

    FellowPlayer123

    Joined:
    Dec 23, 2016
    Posts:
    70
    Hi, so I'm trying to integrate Mirror with a new input system and camera and character controller.

    I don't know why, but this code causes the game to drop from around 180 FPS to around 50FPS!

    What is going on here?

    Code (CSharp):
    1. public override void OnStartAuthority()
    2. {
    3.     cameraRoot.SetActive(true);
    4.     MyGameActions.Player.Look.performed += ctx => OnLook(ctx.ReadValue<Vector2>());
    5.     MyGameActions.Player.Look.canceled += ctx => OnLook(ctx.ReadValue<Vector2>());
    6. }
    7.  
    8. [ClientCallback]
    9. private void OnEnable() => MyGameActions.Enable();
    10.  
    11. ClientCallback]
    12.  private void OnDisable() => MyGameActions.Disable();
    13.  
    14. // this causes game FPS to drop from ~180FPS to around ~50FPS!
    15. public void OnLook(Vector2 lookAxis)
    16. {
    17.     Debug.Log("testing");
    18. }
     
  43. FakeByte

    FakeByte

    Joined:
    Dec 8, 2015
    Posts:
    147
    Is OnLook called every frame? Calling Debu.Log is slow, try removing the log and see if that helps or if the problem is somewhere else.
     
    FellowPlayer123 likes this.
  44. FellowPlayer123

    FellowPlayer123

    Joined:
    Dec 23, 2016
    Posts:
    70
    Yeah, I forgot to write here, but removing Debug.Log was causing the trouble! I didn't know it's so expensive!


    Is there is some operation similar to if(Input.GetKeyDown("Space")),
    but in a new input system?

    Something like:

    Code (CSharp):
    1. void Update () {
    2.     if(MyGameActions.Player.Look.performed)
    3.     {
    4.     }
    5. }
     
  45. HeadZerg

    HeadZerg

    Joined:
    Aug 15, 2014
    Posts:
    18
    You could use
    Keyboard.current.space.wasPressedThisFrame
    .
     
  46. FellowPlayer123

    FellowPlayer123

    Joined:
    Dec 23, 2016
    Posts:
    70
    Yeah, but it's platform-specific. How about using an action map?
     
  47. HeadZerg

    HeadZerg

    Joined:
    Aug 15, 2014
    Posts:
    18
    In that case you could use
    InputAction.triggered
    and
    InputAction.ReadValue<>()
    . InputActions fields are drawn in the inspector by the way.
     
    FellowPlayer123 likes this.
  48. blablaalb

    blablaalb

    Joined:
    Oct 28, 2015
    Posts:
    42
    I need someones help. I'm trying to convert single-player game to multiplayer game played over lan.
    Now I have some objects referencing the player object: camera with camerafollow component for example. Those are local player specific game objects and don't need to be instantiated on server or on other players side.
    I"m struggling to dynamically obtain reference to the spawned player. I raise an event inside
    NetworkManager.OnClientConnect
    :
    Code (CSharp):
    1.     public event Action<NetworkIdentity> Connected;
    2.  
    3.     public override void OnClientConnect(NetworkConnection conn)
    4.     {
    5.         base.OnClientConnect(conn);
    6.  
    7.         Connected?.Invoke(conn.identity);
    8.     }
    and subscribe to the event:
    Code (CSharp):
    1.         internal void Start()
    2.         {
    3.             var nm = FindObjectOfType<NetworkManager>();
    4.             if (nm != null) nm.Connected += (x) =>
    5.             {
    6.                 _player = x.gameObject;
    7.             };
    8.         }
    but this throws NullReferenceException, the NetworkConnection.identity inside OnClientConnect in null
    System.NullReferenceException: Object reference not set to an instance of an object at Player.CameraFollow+<>c.<Start>b__7_0 (Mirror.NetworkIdentity x) [0x00001]

    I'm struggling to understand how can I dynamically obtain a reference to the spawned player. Why the NetworkConnection.identity is null inside OnClientConnect? I thought it should point to the spawned Player game object. How to get reference to the local player object after player connects to the server?
     
  49. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,929
    Mirror Stability progress Update.

    Core Test Coverage now at 79.6%
    -> 'Mirror', 'Mirror.Weaver' Namespaces
    -> Excluding Transports, Components, Editor UIs etc.
    -> Including all [Obsolete]s, so the actual coverage is even higher

    2021-06-17 - 79,6 percent - including obsoletes.png
     
    MilenaRocha, Zeohack and xVergilx like this.
  50. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,929
    NetworkTransform V1 vs. V2 comparison:


    Snapshot Interpolation working beautifully.
    => ~90-100ms latency %15 packet drop.
    => Outside tested by a MOBA project that we can't name yet.

    V2 is currently open for review & testing:
    https://github.com/vis2k/Mirror/pull/2791
     
unityunity