Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    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. 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,854
    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,854
    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:
    81
    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:
    81
    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,854
    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,854
    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,854
    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,854
    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:
    81
  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:
    81
    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:
    81
    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,854
    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:
    81
    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?
     
unityunity