Search Unity

Unity Multiplayer Mirror - Open Source Networking for Unity

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

  1. FellowPlayer123

    FellowPlayer123

    Joined:
    Dec 23, 2016
    Posts:
    74
    Nice! Is this going to replace the NetworkTransform component? When can we expect this update to arrive in AssetStore?
     
  2. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,971
    That's the plan.
    NT2 has heavy test coverage already and is ready to use.
    We just give people a couple of days to test in case we missed anything.
    So far only positive feedback.
     
    FellowPlayer123 likes this.
  3. BlastM

    BlastM

    Joined:
    Jun 17, 2021
    Posts:
    2
    Is there any way to know command successfully sent by client? I need to change a boolean inside function before sending command. But when the client has no internet for a very short time and reconnects (connection established before timeout) my boolean changed and my command didn't received by server. How can I solve this situation? I didn't want to put any delay to changing back my variable.
     
    Last edited: Jul 13, 2021
  4. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,971
    Commands go over reliable channel.
    So they are either guaranteed delivered, or the connection disconnects.
     
  5. FariAnderson

    FariAnderson

    Joined:
    Jan 20, 2020
    Posts:
    16
    Hey mr.vis2k, Will mirror work after UNet removal from Unity? If yes then how? Cuz I've heard it's built on top of UNet.
     
  6. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,971
    Yes :)
     
  7. Alex1337rus

    Alex1337rus

    Joined:
    Mar 30, 2016
    Posts:
    35
    Hello! I want to make game like minecraft or valheim. Is it possible with mirror?
    I just need next things:
    1) A large world that cannot be loaded into memory. (Stored in files and loaded by chunks)
    2) Add blocks
    3) Remove blocks
    4) Synchronize world for all players
    Any examples or tips?
     
  8. pepito233

    pepito233

    Joined:
    Oct 5, 2020
    Posts:
    7
    Good Morning. I have a synchronization problem with clients.

    The server shows the animation of the clients, but the clients do not see the animation of the other clients, nor their own. It only happens with the animation associated with the bool ("zoom").

    I need help, thank you.

    ////////////////////////////////////////////////////////////////

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Mirror;

    public class ActivarMiraArma : NetworkBehaviour
    {
    public Camera cámaraArma;
    public Camera cámaraM4;
    public Camera cámaraBeretta92;
    public Camera cámaraBayesta;
    public Animator anim;
    [SyncVar] public bool zoom = false;
    public float tiempoProgramado = 0.25f;
    public float tiempo;
    public GameObject jugador;
    public GameObject Arma;


    public void Start()
    {
    jugador = this.transform.gameObject;
    }


    public void Update()
    {
    if (isLocalPlayer)
    {
    if (tiempo > 0)
    tiempo -= Time.deltaTime;
    if (anim == null)
    anim = transform.GetComponent<Animator>();
    Arma = GameObject.FindWithTag("ArmaMontada");
    if (Arma == null) return;
    if (Arma.name == "M4")
    {
    cámaraArma = cámaraM4;
    activarCámaraM4();
    }
    if (Arma.name == "Beretta92")
    {
    cámaraArma = cámaraBeretta92;
    activarCámaraBeretta92();
    }
    if (Arma.name == "Crossbow")
    {
    cámaraArma = cámaraBayesta;
    activarCámaraBayesta();
    }
    if (Input.GetMouseButton(1))
    {
    if (zoom == true) return;
    CmdZoomTrue();
    }
    else
    {
    CmdZoomFalse();
    anim.SetBool("Zoom", false);
    zoom = false;
    }
    if (Input.GetMouseButton(0))
    {
    anim.SetBool("Ratón Izquierdo", true);
    }
    else anim.SetBool("Ratón Izquierdo", false);
    }

    }


    [Command]
    void CmdZoomTrue()
    {
    anim.SetBool("Zoom", true);
    zoom = true;
    }
    [Command]
    void CmdZoomFalse()
    {
    anim.SetBool("Zoom", false);
    zoom = false;
    }


    public void activarCámaraBeretta92()
    {
    if (isLocalPlayer)
    {
    cámaraBayesta.enabled = false;
    cámaraM4.enabled = false;
    cámaraBeretta92.enabled = false;

    if (zoom == true)
    {
    temporizador();
    }
    else
    {
    cámaraArma.enabled = false;
    tiempo = tiempoProgramado;
    }
    }
    }


    public void activarCámaraM4()
    {
    cámaraBayesta.enabled = false;
    cámaraM4.enabled = false;
    cámaraBeretta92.enabled = false;
    if (zoom == true)
    {
    temporizador();
    }
    else
    {
    cámaraArma.enabled = false;
    tiempo = tiempoProgramado;
    }
    }


    public void activarCámaraBayesta()
    {
    cámaraBayesta.enabled = false;
    cámaraM4.enabled = false;
    cámaraBeretta92.enabled = false;
    if (zoom == true)
    {
    temporizador();
    }
    else
    {
    cámaraArma.enabled = false;
    tiempo = tiempoProgramado;
    }
    }


    public void temporizador()
    {
    if (tiempo <= 0)
    {
    cámaraArma.enabled = true;
    tiempo = 0;
    }
    }
    }
     
  9. InteractivePie

    InteractivePie

    Joined:
    May 2, 2014
    Posts:
    11
    Hello @vis2k,

    First off I would like to say that I'm very happy with Mirror. Im creating a game and things are looking smooth. I have a question around security for Dedicated servers:

    Say if I upload my server build to an external webserver that is reachable by port 7777. Now I will make another Unity project that connects to the same server but with completely different client code (expecting it would know about the server code). Would it work? Could somebody do something malicious in that case?

    I also wonder the other way around. It would be nice to keep things clear and to have a separate Unity project with only server code, and let another unity project connect to it as client only.

    Or is it intended to have the client and server code in one unity project so that it will always be secure connecting to the dedicated server?
     
  10. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,971
    Most servers run on Linux, where you can see the source code too. Doesn't mean it's not secure :)
    You can use #if UNITY_SERVER to remove server-only code from the client if necessary.
     
  11. BlastM

    BlastM

    Joined:
    Jun 17, 2021
    Posts:
    2
    Hi @vis2k
    Today I tested my game on mobile and something caught my attention. When I close wifi or cellular, on client disconnect function calling without any timeout. This occurs only client side, server fires disconnect event still after timeout. Why?
     
  12. LuxindraGaming

    LuxindraGaming

    Joined:
    Sep 2, 2020
    Posts:
    4
    hi, @vis2k @Tornadoally @tomweiland @TwoTen @PartyBoat I'm new in multiplayer game with mirror networking and I'm still learning. I want one help from you guys, how I join random room and if there is no room available then create its own room. is there any way to do that. if you have any solution with the script please provide.

    Like, I'm making a simple board game and in first scene there will be one button says Play Button. Using this play button player will find random room and if room available then join else create its own room.
    please give a script if you have any.

    Thanks in advance.
     
  13. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,971
  14. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,971
    Mirror V46 LTS (Long Term Support) is live!
    mirror_icon_1200x300_GITHUB_M_smaller.png

    If you use Mirror in production, consider Mirror LTS!

    =>
    Bug fixes only.
    => Consistent API: update any time, without any breaking features.
    =>
    Lives along side Unity 2019 LTS.
    =>
    Supported from Sept. 2021 to Sept. 2022, depending on feedback.

    All GitHub Sponsors are invited automatically.
     
    xVergilx and mgear like this.
  15. Kanyade

    Kanyade

    Joined:
    Jul 9, 2021
    Posts:
    1
    Greetings!

    I only recently discovered Mirror and I'm kind of lost in all of the information available.
    I want a basic 'client sends data to server' method with Mirror, so like inside a function I send some data to the server and the server does whatever it wants with that. The client does not require acknowledgement and if a data is lost then it does not matter, it continues to live its life, so UDP is preferred.

    Can you guide me to somewhere where I can find it out how to do it? Or show a basic example?
    The examples provided consist of too many files and components for me to understand in a day and I would need to solve this as soon as I can.

    The main issue is that for example in the Chat example, the ChatNetwork manager has only like 50 lines of codes, while the button Start server calls the ChatNetwork manager's StartHost function, which I don't see, that's why it is hard to debug to match my case. In the future I would like to work with Mirror, that's why I would like to stick to it now as well.

    Thank you in advance!
     
    Last edited: Sep 9, 2021
  16. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,971
    Hey guys, significant performance update coming.
    https://github.com/vis2k/Mirror/pull/2922

    Previously SyncLists/SyncDicts dirty checks required iterating all the SyncLists/SyncDicts.
    This was O(N) complexity:
    Code (CSharp):
    1.         internal ulong DirtyObjectBits()
    2.         {
    3.             ulong dirtyObjects = 0;
    4.             for (int i = 0; i < syncObjects.Count; i++)
    5.             {
    6.                 SyncObject syncObject = syncObjects[i];
    7.                 if (syncObject.IsDirty)
    8.                 {
    9.                     dirtyObjects |= 1UL << i;
    10.                 }
    11.             }
    12.             return dirtyObjects;
    13.         }
    14.  
    15.         // internal for tests
    16.         // reuses DirtyObjectBits for simplicity.
    17.         internal bool AnySyncObjectDirty() => DirtyObjectBits() != 0UL;
    Now it's O(1) by using a dirty mask:
    Code (CSharp):
    1.  
    2.             // OnDirty needs to set nth bit in our dirty mask
    3.             ulong nthBit = 1UL << index;
    4.             syncObject.OnDirty = () => syncObjectDirtyBits |= nthBit;
    A lot of people noticed the old code showing up in the profiler.
    Not anymore :)
     
    hopeful likes this.
  17. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,971
    Next major performance improvement.
    https://github.com/vis2k/Mirror/pull/2923

    Previously, NetworkServer.Update iterated all connections and all spawned entities.
    With this change, it only has to iterate all connections.

    This is huge for scaling.
     
  18. Obay_naeem

    Obay_naeem

    Joined:
    Jan 22, 2020
    Posts:
    4
    hey guys
    am currently working on a online multiplayer game and I'm using mirror as network solution.
    the game it self is rather simple ,it's a glass marble ball match whenever a player throws a ball he own and it collides with other players balls he become the owner of the ball he collides with.

    the plan is to make a multiple matches that the server can handle separately ,but as i understood from mirror examples physics based rooms (or matches) should be on separate game server instances (copies of the mirror server application)

    " because as i understood although the players on a single match can't see or interact with other players from other match's (because of the network match component) all the players balls from all matches exits on the server in one place which lead to an unwanted problems (that's what I think at least)".

    but mirror dose not support matchmaking like i describe
    and i can't figure out a way to do that on a remote machine(a dedicated server) containing my mirror server.
    can someone help to find a way to do that, and thanks .
     
    Last edited: Oct 14, 2021 at 12:07 PM
unityunity