Search Unity

Showcase Mirror - Open Source Networking for Unity

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

  1. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    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.
     
  2. mischa2k

    mischa2k

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

    Piflik

    Joined:
    Sep 11, 2011
    Posts:
    293
    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
  4. 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
  5. PartyBoat

    PartyBoat

    Joined:
    Oct 21, 2012
    Posts:
    97
    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.
     
  6. mischa2k

    mischa2k

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

    juangenial452

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

    Enignum

    Joined:
    Feb 28, 2017
    Posts:
    8
    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
  9. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    If you rebuild your server, also make sure to rebuild your client.
     
  10. Enignum

    Enignum

    Joined:
    Feb 28, 2017
    Posts:
    8
    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 :(
     
  11. mischa2k

    mischa2k

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

    Enignum

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

    Emperor

    Joined:
    Feb 13, 2014
    Posts:
    41
    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);
     
  14. NocSchecter

    NocSchecter

    Joined:
    Aug 19, 2015
    Posts:
    33
    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.
     
  15. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    368
    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.
     
    mischa2k likes this.
  16. patrick750

    patrick750

    Joined:
    Nov 29, 2019
    Posts:
    14
    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
  17. TheUninvited

    TheUninvited

    Joined:
    Jun 22, 2018
    Posts:
    31
  18. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Hey guys, check out what's possible with Mirror:
     
    DBarlok, Joe-Censored and zhn17 like this.
  19. BobyUnity

    BobyUnity

    Joined:
    Apr 9, 2019
    Posts:
    30
    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?
     
  20. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    :)
     
    Last edited: May 1, 2020
    hopeful likes this.
  21. BobyUnity

    BobyUnity

    Joined:
    Apr 9, 2019
    Posts:
    30
    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.
     
    mischa2k likes this.
  22. 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
     
  23. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    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.
     
  24. vspin

    vspin

    Joined:
    Mar 29, 2014
    Posts:
    22
    "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.
     
  25. vspin

    vspin

    Joined:
    Mar 29, 2014
    Posts:
    22
    I guess this post addresses my question: https://forum.unity.com/threads/rem...attributes-without-using-compiler-ifs.447542/
     
  26. 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
  27. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    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 :)
     
  28. 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
  29. Tset_Tsyung

    Tset_Tsyung

    Joined:
    Jan 12, 2016
    Posts:
    411
    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.
  30. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    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.
  31. Piflik

    Piflik

    Joined:
    Sep 11, 2011
    Posts:
    293
    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?
     
  32. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    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?
     
  33. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Your iPad's firewall is blocking the connection. That's normal.
    Maybe you can allow it somewhere in iPad settings.
     
  34. BobyUnity

    BobyUnity

    Joined:
    Apr 9, 2019
    Posts:
    30
    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?
     
  35. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    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.
     
    mischa2k likes this.
  36. 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
  37. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    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.
     
  38. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    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
  39. akuno

    akuno

    Joined:
    Dec 14, 2015
    Posts:
    88
    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
  40. Daxten

    Daxten

    Joined:
    Sep 20, 2013
    Posts:
    30
    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?
     
  41. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    What does HexCell look like?
     
  42. Daxten

    Daxten

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

    gillemp

    Joined:
    Nov 23, 2015
    Posts:
    81
    It did not work for me though...
     
  44. BobyUnity

    BobyUnity

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

    castana1962

    Joined:
    Apr 10, 2013
    Posts:
    400
    Hi Everyone. Sorry for my ignorance but I am new in this topic but I would need to do a multiplayer setup over the network to can make a test setup with Mobile and a PC version where I try to synchronize two players, for it, Could anybody say me how I can do it with Mirror?
    On the other hand and for that you can understand better what my main goal is.
    I am building Recovery Treatments for people with Motor and Cognitive problems through VR Video Games and I am thinking in adding to it the Asymmetric Virtual Reality function so that the patient plays in Virtual way (with the VR Headset) and their friends or family in a non-virtual way and through joysticks or cell phones interact with the patient into the same VR game with the aim of empowering and helping the patient achieve him/her goals.Hopefully you can understand me. Thanks for your time
     
    Last edited: May 31, 2020
  46. MonkeyS_Finger

    MonkeyS_Finger

    Joined:
    Nov 11, 2017
    Posts:
    7
    Hi, could you please tell me how can I implement [Command] atribute ignoring authority?
    I know that for security reasons this is not allowed, but I really need this for testing purpouses and this will be only for my personal use.

    I've found the code where you check the authority, but I just want to give [Command] a paramenter, or create a new [CommandNoAuth] for this specific task, i don't want to mess with the [Command] attribute code.
    can you please help me?
    I hope you could help me about this, I'm struggling to understand how the [Command] atribute works to make another one, but i'm going crazy.

    Thanks.
     
  47. hungrybelome

    hungrybelome

    Joined:
    Dec 31, 2014
    Posts:
    336
    Vincent454 likes this.
  48. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
  49. MarkoHazel

    MarkoHazel

    Joined:
    Apr 5, 2020
    Posts:
    15
    Hi,

    I have this code which I use in a card game to load images from a directory onto card prefabs and I want it to work with networking so each player can load in their own deck of cards with unique PNG images into the game:
    Code (CSharp):
    1. foreach (string gameobject in string list)
    2.             {
    3.  
    4.                 GameObject = Instantiate(spawnableprefab);
    5.                 byte[] bytes = File.ReadAllBytes(gameobject);
    6.             NetworkReaderPool.GetReader(bytes);
    7.             Texture2D texture = new Texture2D(1, 1);
    8.                 texture.LoadImage(bytes);
    9.                 gamobjectimage = GameObject.GetComponent<Image>();
    10.                 gamobjectimage.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
    11.         }
    Is there a method with Mirror that will allow each client to see the loaded PNGs from their end? Any examples would be greatly appreciated :)
     
    DomeCreator likes this.
  50. stanek_unity

    stanek_unity

    Joined:
    Jun 16, 2019
    Posts:
    10
    [Command(ignoreAuthority = true)]
     
    mischa2k likes this.