Search Unity

Unity Multiplayer Mirror - Networking for Unity (UNET Replacement)

Discussion in 'Connected Games' started by vis2k, Aug 11, 2016.

  1. csofranz

    csofranz

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

    zhn17

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

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,180
    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.
  4. zhn17

    zhn17

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

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,442
    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.
  6. zhn17

    zhn17

    Joined:
    Jul 30, 2019
    Posts:
    24
    Seems to work for the mounting and dismounting (haven't had time to do it for the horse yet), thanks for the help!
     
  7. 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?
     
    bigfootaus likes this.
  8. 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?
     
  9. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,442
    Try to host the chat server on a vps/dedicated/cloud server on the internet.
     
    KAYUMIY likes this.
  10. 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?
     
  11. zhn17

    zhn17

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

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,442
    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.
  13. KAYUMIY

    KAYUMIY

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

    vis2k

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

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,442
    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
     
  16. itzikpel

    itzikpel

    Joined:
    Mar 27, 2015
    Posts:
    15
    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.
  17. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,442
    bigfootaus, hopeful and Joe-Censored like this.
  18. patSilva

    patSilva

    Joined:
    Mar 25, 2019
    Posts:
    6
    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.
     
  19. 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.
  20. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,442
    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.
  21. Piflik

    Piflik

    Joined:
    Sep 11, 2011
    Posts:
    242
    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
  22. 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!
     
  23. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,442
    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.
     
  24. vis2k

    vis2k

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

    Piflik

    Joined:
    Sep 11, 2011
    Posts:
    242
    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
  26. MonkeyS_Finger

    MonkeyS_Finger

    Joined:
    Nov 11, 2017
    Posts:
    5
    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 at 12:20 AM
unityunity