Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Unity Multiplayer Mirror - Open Source Networking for Unity

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

  1. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,960
  2. patSilva

    patSilva

    Joined:
    Mar 25, 2019
    Posts:
    27
    I believe so, and I also think you can achieve a lot of what you want with NetworkTransformChild. Add that component to the parent and set its target to the child you want. In my experience I have used multiple NetworkTransformChild components on the same Parent so it could track multiple Network Identities. So multiple players could enter the bus. Also the parenting and unparenting would be done the same way in case number two with the added step of resetting the car's client authority to false.
     
  3. GuiTeK

    GuiTeK

    Joined:
    Apr 28, 2017
    Posts:
    10
    Hi Mirror enthusiasts!

    Congratulations to all the Mirror contributors for the amazing work! It's impressive to see the progress made in just a few months (not only in terms of code, but also documentation, video tutorials, etc.). The KISS approach of Mirror and the hard work you put into this project to make it reliable result in such a great Developer eXperience, and it allows us to move forward quickly with our games! Thank you!

    I got a quick question: when is/should ClientScene.AddPlayer() be called? Currently I have this function in my server code:
    Code (CSharp):
    1. public override void OnServerAddPlayer(NetworkConnection conn)
    2. {
    3.     base.OnServerAddPlayer(conn);
    4. }
    Which is called when the client calls ClientScene.AddPlayer() and basically adds a player for this connection.
    However, as I spawn the player manually server-side, should this ever be called? I'm concerned by malicious clients calling this while they should not.
     
    vis2k likes this.
  4. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,960
    Thanks mate.
    We kept the naming from UNET, and it's a bit confusing.
    ClientScene.AddPlayer doesn't really add a player. it just asks the server to add a player, after which OnServerAddPlayer is called.
    If you instantiate+spawn your player manually, then you don't need to call the base function.
    If you need help I can post a snippet of uMMORPG's NetworkManager code, where I do that too.
     
    Joe-Censored likes this.
  5. Piflik

    Piflik

    Joined:
    Sep 11, 2011
    Posts:
    274
    I have an issue with spawning a customized player. I followed the Docs to send a message containing the configuration. This works only on the Host instance of the application, but for all player objects. On the client, the registered message handler doesn't get called. I tried registering it in OnStartClient, too, but that didn't change anything.
    Can anybody tell me what I am doing wrong?
     
    Last edited: Mar 26, 2020
  6. ronnansouza

    ronnansouza

    Joined:
    Feb 21, 2019
    Posts:
    1
    Hello everyone, is there any way to measure packet loss between client and server using Mirror? I've been reading about using UNet I can't anything reliable. Thanks in advance!
     
  7. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,960
    Please open an issue on our issue tracker with steps to reproduce.

    Mirror's default transport - Telepathy - uses TCP. Packet loss doesn't really matter there, TCP already takes care of it.
    So we don't have a way to measure this by default.
     
  8. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,960
    Joe-Censored and hopeful like this.
  9. Piflik

    Piflik

    Joined:
    Sep 11, 2011
    Posts:
    274
    I have two questions.

    1. Is there a mechanism built into Mirror to stream arbitrary data to clients (for example a byte array). The data doesn't have to be updated in realtime, so it can be transferred over multiple frames.

    2. Is it possible for clients that are connected to the same server to be in different scenes (without additive scene loading), so they don't see each other or even get synchronized until they meet in one single scene?
     
    Last edited: Mar 31, 2020
  10. MonkeyS_Finger

    MonkeyS_Finger

    Joined:
    Nov 11, 2017
    Posts:
    7
    I'm trying to load additive scene using mirror networkig.
    In past i've used networkIdentity.ForceSceneId() to forsce scene Id to avoid collisions between id in different scenes, but now the ForceSceneId method isno longer available in the networkIdentity.
    there is something different that I can do?
    there is a way to safely load additive scene with Mirror?

    I've seen that here: https://github.com/vis2k/Mirror/pull/175 seems that a solution for additive is found and maybe I have to not worry about async scene loading.
    Is this true? there is an example on how to load now additive scene?

    i'm struggling for help, thanks.
     
    Last edited: Apr 8, 2020
  11. PartyBoat

    PartyBoat

    Joined:
    Oct 21, 2012
    Posts:
    94
    Hey @vis2k do you know if Mirror supports the new fast enter play mode feature Unity has now or if it will in the future? Specifically I was wondering if Mirror could handle having domain reloads turned off. Considering that without domain reloads static fields and static event handlers aren't reset I'd figure that if Mirror wasn't built with this in mind that it would cause some sneaky issues while testing the game in the editor.
     
  12. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,960
    It does not.
    Fast enter playmode is for Dots.
    Most MonoBehaviour assets use static state because it was fine for the last 10 years.
     
  13. juangenial452

    juangenial452

    Joined:
    Apr 13, 2020
    Posts:
    5
    Is there any way to make a Telepathy or WebSocket server for Mirror using node.js?
     
  14. Enignum

    Enignum

    Joined:
    Feb 28, 2017
    Posts:
    7
    Hi,
    If I build my server as "Server Build" I'm getting "Unknown message ID 33978 connection(0)"
    Can it be because I built whole server as Host and not just as Server?

    Thanks
     
    Last edited: Apr 16, 2020
  15. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,960
    If you rebuild your server, also make sure to rebuild your client.
     
  16. Enignum

    Enignum

    Joined:
    Feb 28, 2017
    Posts:
    7
    I did but still the same...
    in other words: can I use StartHost() in server in headless mode ("Server Build" option enabled)? Because that's the only thing that is coming to my mind :(
     
  17. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,960
    Read the documentation please :) :)
    Headless mode is server-only. There is no host mode.
     
  18. Enignum

    Enignum

    Joined:
    Feb 28, 2017
    Posts:
    7
    Ooooo... that explains why it's not working :)
    Thanks!
     
  19. Emperor

    Emperor

    Joined:
    Feb 13, 2014
    Posts:
    39
    I want my server (and maybe clients) to spawn objects that have custom 3d models that are generated at runtime. The clients won't have the 3d mesh/texture/etc assets basically but the server should send them that info so that they can see it when it spawns.

    I'm not sure how to go about doing this after reading the doc quick. Is that stuff below (from the doc) enough? Or do I need to do something more to transfer the assets of the custom 3d models?


    Code (CSharp):
    1. // generate a new unique assetId
    2. System.Guid creatureAssetId = System.Guid.NewGuid();
    3.  
    4. // register handlers for the new assetId
    5. ClientScene.RegisterSpawnHandler(creatureAssetId, SpawnCreature, UnSpawnCreature);
    6.  
    7. // get assetId on an existing prefab
    8. System.Guid coinAssetId = coinPrefab.GetComponent<NetworkIdentity>().assetId;
    9.  
    10. // register handlers for an existing prefab you'd like to custom spawn
    11. ClientScene.RegisterSpawnHandler(coinAssetId, SpawnCoin, UnSpawnCoin);
    12.  
    13. // spawn a coin - SpawnCoin is called on client
    14. NetworkServer.Spawn(gameObject, coinAssetId);
     
  20. NocSchecter

    NocSchecter

    Joined:
    Aug 19, 2015
    Posts:
    32
    Hi,

    I am creating a small server using Mirror, Congratulations! I like it better than Unity, it is very powerful.

    I am trying that when a new client connects to the server it can obtain everything that is happening on the server, that is, the position of the clients already connected, what they are doing, number of deaths per client, user with the highest score, etc.

    Can you give me a very basic example or guide me on how to implement it? I honestly can't find a way to do it.

    Thanks.
     
  21. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    340
    Pretty much all of that would be handled through SyncVars on the player objects. You can read about these in our docs, and find us in Discord if you get stuck.
     
    vis2k likes this.
  22. patrick750

    patrick750

    Joined:
    Nov 29, 2019
    Posts:
    9
    Edit: Ignore, completely solved. Character Controller was being relied upon for ray hit and it was disabled for the local player on other client objects (obviously). Added a collider to the player prefab and all fixed.

    I'm working with Mirror and trying to make a targeting system similar to WoW; the client runs a raycast and activates the target frame when it finds a hit with the 'player' tag. I figure this is something that doesn't need to be done on the server.

    This works fine on the client to target myself/non player gameobjects but my raycast does not detect other players on the server. I'm printing every object the ray hits but other client's players don't seem to exist to the ray. Any idea about how to fix this?

    Code (CSharp):
    1. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    2.             RaycastHit[] hits = Physics.RaycastAll(ray);
    3.  
    4.             foreach (RaycastHit hit in hits)
    5.             {
    6.                 print(hit.transform.gameObject.name);
    7.                 if (hit.transform.gameObject.tag == "Enemy" || hit.transform.gameObject.tag == "Player")
    8.                 {
    9.                     targetOnMouseUp = hit.transform.gameObject;
    That is the gist of what I'm doing on the client.
     
    Last edited: Apr 23, 2020
  23. TheUninvited

    TheUninvited

    Joined:
    Jun 22, 2018
    Posts:
    31
  24. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,960
    Hey guys, check out what's possible with Mirror:
     
  25. BjornG

    BjornG

    Joined:
    Apr 9, 2019
    Posts:
    27
    Did someone ever try to use ECS with Mirror? Would probably take quite some workarounds I guess but since I now build up a bit of knowledge in the Unity DOTS Universe I of course wonder if I will ever be able to use this knowledge in a networking environment outside of the Unity DOTS Networking (that is far from ready actually). Do you have plans on something like ECS integration?
     
  26. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,960
    :)
     
    Last edited: May 1, 2020
    hopeful likes this.
  27. BjornG

    BjornG

    Joined:
    Apr 9, 2019
    Posts:
    27
    What the actual F*** :D
    You posted it today? Awesome! I guess I found the networking solution that I will stick with ;)
    Thanks for your dedication. Still will first try to develop skills with the Mono/Networkbehaviour stuff before I continue with my hate/love relationship with Entities.
     
    vis2k likes this.
  28. castana1962

    castana1962

    Joined:
    Apr 10, 2013
    Posts:
    400
    Hi
    Sorry for my ignorance but I am new in this topic...
    Since I am making Recovery treatments for Human health problems by VR games and I am interested in adding Asymmetrical VR features to play 'crossplay' between VR and non-VR users ( for example in the Pizza Master VR game), For it, Could I build this Asymmetric VR feature with the Mirror plugin ? Would it be possible?)
    Thanks for your time
     
  29. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,960
    That should be fine :)
    The #1 game on our showcase is Population: ONE, which is a VR game too.
    As far as I know, Mirror has treated them well.
     
  30. vspin

    vspin

    Joined:
    Mar 29, 2014
    Posts:
    12
    "With Mirror, the Server & Client are ONE project (hence the name). "

    I love what I'm reading! However, while there's "ONE project," can I have two builds with one being strictly a server, and the other being strictly a client with NO server code? The tutorials I've read/watched so far produce a single multipurpose client/server build which won't work for me.
     
  31. vspin

    vspin

    Joined:
    Mar 29, 2014
    Posts:
    12
    I guess this post addresses my question: https://forum.unity.com/threads/rem...attributes-without-using-compiler-ifs.447542/
     
  32. Chefty

    Chefty

    Joined:
    Jun 17, 2015
    Posts:
    43
    Hi everyone !
    I'm currently having a big issue with NetworkAnimator:
    First of all, I want to say that I use StateMachineBehaviour to manage my animations. In the end, it doesn't seems to work as well as setting up animation parameters through a simple Update.
    As you can see on this video, the punch animation is not always playing in the editor (server only) but works perfectly on build window (client).
    If you look even closer, I have a sphere collider attached to the player's hands that I set at the same place in my code (by calling a cmd on the player) and it is perfectly synced on client and server side.
    Only the animation is not syncing up correctly (unless I spam the inputs), which is quite a problem for a "fist fighting video game".
    Am I missing something important here ? Or StateMachineBehaviour and mirror might not be that compatible ?
    Not sure if it is relevant enough to open an issue on Github so I post it here first.
    Thanks in advance for your help.
     
    Last edited: May 7, 2020
  33. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,960
    The best way to sync animations is to do not sync them.
    You probably already have the state on the client anyway, like player speed, rotation, etc. - just feed that to the animator locally :)
     
  34. Chefty

    Chefty

    Joined:
    Jun 17, 2015
    Posts:
    43
    Sorry if I wasn't clear enough. I don't sync animation over network myself, I just set animator parameters locally on local player. What I meant is I expect NetworkAnimator to sync these animations properly on the server and then for other clients connected. It just doesn't work as expected as you can see in the video.
     
    Last edited: May 7, 2020
  35. Tset_Tsyung

    Tset_Tsyung

    Joined:
    Jan 12, 2016
    Posts:
    389
    Quick check: Is this thread the best to post questions/bugs about using Mirror Networking? If not, does anyone know where the best place to get help is?
     
    Chefty likes this.
  36. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,960
    Bugs on our issue tracker please: https://github.com/vis2k/Mirror/issues
    For questions, the thread is fine. Discord is probably easier (see my signature)
     
    Tset_Tsyung likes this.
  37. Piflik

    Piflik

    Joined:
    Sep 11, 2011
    Posts:
    274
    I am currently trying to do a really basic thing: move an object that is already in the scene. I call
    NetworkIdentity.AssignClientAuthority(connectionToClient)
    and
    NetworkTransform. clientAuthority = true
    via a Command. The second one I also call directly on the Client. If I omit any of the three elements, even though the call to
    NetworkTransform. clientAuthority = true
    on the client seems redundant, the position is not synchronized in the network. Not sure if this is the correct way to prepare an object to be moved by a client, but it seems to work. I have a similar Command to return authority back to the server.

    However, I now have the issue that the server automatically despawns the object when the client holding authority over it disconnects. I have no idea how to prevent this and instead simply return authority back to the server. I tried calling the code to return authority in
    OnStopClient
    ,
    OnStopAuthority
    ,
    OnDestroy
    and in the
    Application.quitting
    callback (all on the network behaviour that currently holds authority), but none of these work.

    What is the correct way to take and release ownership over an object in order to move it somewhere else?
     
  38. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,228
    Hi,

    I am absolutely new to networking and want to reach this little goal:

    Connect iPad-App (as server) to PC-Executable (as client)
    and transfer touchposition to a sprite on the PC.

    As long as I try this from PC-Executable to PC-Editor it works fine.

    But when I have the App on my iPad it doesn´t connect:

    "Client Recv: failed to connect to ip=localhost port=7777 reason=System.Net.Sockets.SocketException (0x80004005): Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte."

    What should I do?
     
  39. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,960
    Your iPad's firewall is blocking the connection. That's normal.
    Maybe you can allow it somewhere in iPad settings.
     
  40. BjornG

    BjornG

    Joined:
    Apr 9, 2019
    Posts:
    27
    Is it possible to spawn Objects that are not enlisted in the "Registered Spawnable Prefabs" Section of the Networkmanager? Since I would like to try to transfer bigger .fbx over network to another client to than implement and move them synchronously I would have to spawn them with out them being enlisted. Does someone have suggestions for this procedure?
     
  41. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,521
    You could consider just spawning and controlling a base prefab which has no model, and you just attach the model to it client side after you've transferred and done your runtime import of the model. Then it isn't even a networking issue outside of the model transfer itself.
     
    vis2k likes this.
  42. JorgeWilson10

    JorgeWilson10

    Joined:
    May 18, 2020
    Posts:
    1
    Hello vis2k great job with mirror thanks you and your team.
    I'm really new in networking, i'd like to ask you:
    ¿What dedicated servers you recomend me to a game with around forty people? (This working with mirror)
    I'll pay to dedicated servers because i will need to transfer the authority to the client, and the client doesn't works with firewalls and ports (escapes his knowledge). ¿ I'm right with that decision or have other alternativies?

    thanks u very much.
     
    Last edited: May 20, 2020
  43. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,960
    I use Google Cloud for all my hosting. Amazon is probably good too.
    What's great about all the cloud hosting is that you can create new servers instantly without anyone having to process your payment, and you can make them faster/slower any time you want.
    They even have a 'f1-micro' instance which is free forever. We tested it with a handful of players and a small game. If you are lucky, it works with your 40 player game too.
     
  44. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,228
    There are no firewall settings on iPads in general.
    Using the Basic-Example, what do I have to enter in the "localhost"-adressfield, both on my PC and on my iPad?
    Are there any ports I have to manually open on my router?
     
    Last edited: May 20, 2020
  45. akuno

    akuno

    Joined:
    Dec 14, 2015
    Posts:
    42
    How can I visualize a SyncList with a simple struct in the editor? I tried using custom drawers, but couldnt get it to work.


    On the picture:
    TimeStampedPosition is a simple struct { Vector3, Float, Int }
    localTimeStamps is a List<TimeStampedPosition>
    serverTimeStamps is a SyncList<TimeStampedPosition>

    I'd like to see the values of elements inside serverTimeStamps, similar to localTimeStamps


    upload_2020-5-25_13-46-26.png
     
    Last edited: May 25, 2020
  46. Daxten

    Daxten

    Joined:
    Sep 20, 2013
    Posts:
    24
    Hi guys, first of all thanks for the great work. This is a great abstraction for networking!

    2 Questions, first of all is there any way to force a specific order in which spawned objects are initialized client side? From my understanding it is not necessarily in the order the server spawned them right?

    Secondly, is this discouraged:
    Code (CSharp):
    1. public static class HexCellReaderWriter
    2. {
    3.     public static void WriteHexCell(this NetworkWriter writer, HexCell cell)
    4.     {
    5.         writer.WriteUInt32(cell.netId);
    6.     }
    7.    
    8.     public static HexCell ReadHexCell(this NetworkReader reader)
    9.     {
    10.         return NetworkIdentity.spawned[reader.ReadUInt32()].GetComponent<HexCell>();
    11.     }
    12. }
    And if not, could it be that there is some kind of generalization we could add to Mirror, so this is not needed for NetworkBehaviours?
     
  47. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,960
    What does HexCell look like?
     
  48. Daxten

    Daxten

    Joined:
    Sep 20, 2013
    Posts:
    24
    It is a NetworkBehaviour with a bunch of SyncVar's and some logic
     
  49. gillemp

    gillemp

    Joined:
    Nov 23, 2015
    Posts:
    76
    It did not work for me though...
     
  50. BjornG

    BjornG

    Joined:
    Apr 9, 2019
    Posts:
    27
    So the idea is to change the prefab in the background while its not spawned allready! Sounds good! Thanks
     
unityunity