Search Unity

Unity Multiplayer Mirror - Networking for Unity (UNET Replacement)

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

  1. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    For 16 players a VPS should be sufficient yes. But if you want to make money with your game, it might be smart to get a dedicated server to have a consistent gameplay quality over time.

    Ubuntu is recommended because of Unity's server-build mode. As far as I know, Unity only has a -nographics mode for Windows. Linux is generally recommended for server hosting anyway.
     
  2. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    296
    Server Build is a console app in Windows...works great.
     
    vis2k likes this.
  3. LeetRooster

    LeetRooster

    Joined:
    Jul 20, 2013
    Posts:
    17
    Hi, I am seeing this error when I add NetworkTransform to a few objects in the root of my scene. They are just some simple moving cubes.

    They load up on the server just fine, but when I connect a client. It doesn't know about these objects and prints these errors.

    Code (CSharp):
    1. "Did not find target for sync message for 1"
    Based on the debug logging, I can tell that the client is never told about these objects, and doesn't know their Network Ids. It gets updates for them, but doesn't ever spawn/enable them, and never adds their network ids to the static NetworkIdentity.spawned dictionary.

    I was able to get player to spawn and have that synced properly, but creating a few objects in the scene itself. The client doesn't seem to get knowledge of them and produces this error

    Shouldn't the client instantiate these objects as well, when it connected to the scene? Is there some mechanism I need to setup for this? It seems like a common use case. A client would want to know about all the existing objects the server has already created when it connects to the scene. Or is this functionality not there? Or does it have something to do with the fact that I just inserted these in the scene, rather than spawned them with a prefab?

    The prefabs for these objects are in the NetworkManager's RegisteredSpawnablePrefabs
     
  4. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    Did you rebuild the client after modifying the server?
    Is there a way to reproduce the issue with one of our built in examples?
     
  5. stanislavdol

    stanislavdol

    Joined:
    Aug 3, 2013
    Posts:
    269
    Thank you!

    But how would you recommend to proceed for a room based game?
    Split a dedicated server into VPSs and run 1 instance on each(1 room/instance per vps) or just run multiple instances right on the server?
     
  6. Eimyfabiolacr

    Eimyfabiolacr

    Joined:
    Dec 14, 2018
    Posts:
    4
    Hi hello i have Umoba and i use that vide for update to mirror but have that 2 error
    1
    (Assets\Mirror\Runtime\Transport\LLAPITransport.cs(26,16): error CS0246: The type or namespace name 'ConnectionConfig' could not be found (are you missing a using directive or an assembly reference?))
    2
    Assets\Mirror\Runtime\Transport\LLAPITransport.cs(53,16): error CS0246: The type or namespace name 'GlobalConfig' could not be found (are you missing a using directive or an assembly reference?)

    thx for help in this video
     
  7. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    The latest uMOBA version should work with Mirror if you use Unity 2018.3. I updated it to Mirror last week.
     
  8. Oscar-Tsang

    Oscar-Tsang

    Joined:
    Nov 7, 2012
    Posts:
    71
    Migration from UNET to mirror is not simple, many function is broken.

    e.g. If you inherit NetworkLobbyManager.

    if you implement OnLobbyServerCreateLobbyPlayer, you cannot do it. Because you cannot access "lobbyPlayerPrefab" on your inherit. Also "playerPrefab" is not accessible too.

    maxPlayers variable is missing. minPlayers not accessible.

    Of cause, you can direct edit NetworkLobbyManager file to solve your problem. But if as a Lib SDK, no one want to edit every time when update the SDK.

    For NetworkLobbyPlayer file, where is the replacement of "SendReadyToBeginMessage"? I have no idea.

    Lack of document, how to implement mirror is the problem. Fully follow UNET function workflow, can solve the lack of document problem. Mirror has reimplement almost 90%, but the 10% different. Make other difficult to find where is the problem.
     
    Player7 likes this.
  9. LeetRooster

    LeetRooster

    Joined:
    Jul 20, 2013
    Posts:
    17
    It happened when I selected IsServer on an onbject I added NetworkTransform to. I think that's not a valid configuration. ServerOnly should be used for like some data objects invisible to the clients. So its purposefully not spawned on the other clients.

    Thanks for the help, but not having the issue anymore
     
  10. LeetRooster

    LeetRooster

    Joined:
    Jul 20, 2013
    Posts:
    17
    What is the intended behaviour with disabling game objects?

    I have a player with two network transform children. I use this to toggle between third person and first person modes. When I disable the gameobjects on one client, its not propogated to the other. I thought that NetworkTransform or NetworkTransformChild classes would handle this behaviour and propagate/mirror the enabled state to the other client.

    Note: I do not disable the root gameobject on the player perfab (which contains all of the NetworkTransform and NetworkTransformChild components)

    Is this incorrect?
     
    Last edited: Jun 3, 2019
  11. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    It's better not to disable anything by yourself when using UNET or Mirror, because it disables/enables things internally to handle areas of interest.
    What you can do is use GetComponent<NetworkProximityChecker>().forceHidden = true.
     
  12. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    Update: NetworkTransform now uses .localPosition and .localRotation for proper VR support :)
     
    Hypertectonic and HeadClot88 like this.
  13. MonkeyS_Finger

    MonkeyS_Finger

    Joined:
    Nov 11, 2017
    Posts:
    4
    It's possible to use Mirror on Android devices?
     
    Last edited: Jun 4, 2019
  14. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    Sure
     
  15. tapticc

    tapticc

    Joined:
    Jan 16, 2014
    Posts:
    365
    I get the idea of a lobby manager, and when the players are ready then start the game on the server and take the players with you, but where do you begin with multiple servers / lobbies?

    There are 2 scenarios I am thinking, the first being a 5v5 team game but lots of active games once there are enough players.

    The second option is each game server instance to be always running and players are directed to the server from some other process, but what is the best way to pass players directly to a specific server? If that server is too full (max player count reached) do you need an overall game server to keep track on player counts per server?
     
    stanislavdol and mpaddon like this.
  16. stanislavdol

    stanislavdol

    Joined:
    Aug 3, 2013
    Posts:
    269
    I asked a somewhat similar question:
    Is it possible to run multiple unity server instances on one dedicated server(each handling a separate room)? I mean, I don't see why not, just would like to confirm in order to avoid any pitfalls
     
  17. LeetRooster

    LeetRooster

    Joined:
    Jul 20, 2013
    Posts:
    17
    I see, is there some place I Can read up on best practices like these? This sort of thing didn't seem to obvious from the component docs I read on the docs site.

    Also, I tried using the GetComponent<NetworkProximityChecker>().forceHidden and the object was still visible. I am not quite clear on how to use this.

    Do I put a component on every child/descendant object that has a Renderer component?
    Or do I only attach the NetworkProximityChecker on the root spawned object?
    Can I use it on NetworkChild transforms as well?
    Since I am using forceHidden, do I also need to setup colliders?
     
  18. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    Please try the latest Mirror version again. We fixed a forceHidden bug 5 minutes ago: https://github.com/vis2k/Mirror/pull/893
    Now the expected behaviour is: if you set your player to forceHidden then no one sees it except himself.
    Players always need to see themselves otherwise you lose the client connection so to speak.
     
  19. ThomasLightweave

    ThomasLightweave

    Joined:
    Sep 30, 2016
    Posts:
    26
    I am using Mirror with the Ignorance transport layer for a AR based arena game. One of the issues I'm having at the moment is a pretty large dropout when a device roams from one WAP to another (Ubiquity WAPs running WPA2 Personal security). I am going to play around with the settings of the WAPs and make sure fast roaming is properly working and everything and that the iPhone7 devices are setup correctly.

    But I was wondering from the unity/networking side whether there would be any steps to improve the perceived disconnection time as the phone roams between WAPs?

    Also a huge thanks for what you all have done here, Mirror is awesome.
     
    vis2k likes this.
  20. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    Probably a good idea to join our discord and talk to the UDP transport devs, namely Coburn and Petris.
    We have Ignorance(ENET), Litenetlib, LLAPI as options for UDP. I recommend trying all three transports to see which one works best in your situation.
     
  21. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    Small Update: Mirror's default Telepathy (TCP) transport now works with both IPv4 and IPv6!
     
  22. abdulraheem_taha

    abdulraheem_taha

    Joined:
    Jun 26, 2018
    Posts:
    1
    I'm a beginner in Networking so excuse my question. Is it possible to use a Shared Hosting Server with Mirror? Or you need a Dedicated/VPS server to make it work properly (Regardless speed and bandwidth differences).
     
  23. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    VPS/Dedicated are required
     
  24. CameronBondeSAE

    CameronBondeSAE

    Joined:
    Feb 9, 2017
    Posts:
    2
    Howdy, I added an AnimationCurve variable and now Mirror is complaining. The first error is the main one (which then causes loads more)

    Code (CSharp):
    1. Mirror.Weaver error: UnityEngine.AnimationCurve is not a supported type
    2. UnityEngine.Debug:LogError(Object)
    3. Mirror.Weaver.CompilationFinishedHook:HandleError(String) (at Assets/Plugins/Mirror/Editor/Weaver/CompilationFinishedHook.cs:42)
    4. Mirror.Weaver.Log:Error(String) (at Assets/Plugins/Mirror/Editor/Weaver/Program.cs:20)
    5. Mirror.Weaver.Weaver:Error(String) (at Assets/Plugins/Mirror/Editor/Weaver/Weaver.cs:174)
    6. Mirror.Weaver.Readers:GetReadFunc(TypeReference, Int32) (at Assets/Plugins/Mirror/Editor/Weaver/Readers.cs:97)
    7. Mirror.Weaver.Readers:GenerateStructReadFunction(TypeReference, Int32) (at Assets/Plugins/Mirror/Editor/Weaver/Readers.cs:273)
    8. Mirror.Weaver.Readers:GetReadFunc(TypeReference, Int32) (at Assets/Plugins/Mirror/Editor/Weaver/Readers.cs:92)
    9. Mirror.Weaver.NetworkBehaviourProcessor:ProcessNetworkReaderParameters(TypeDefinition, MethodDefinition, ILProcessor, Boolean) (at Assets/Plugins/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs:613)
    10. Mirror.Weaver.RpcProcessor:ProcessRpcInvoke(TypeDefinition, MethodDefinition) (at Assets/Plugins/Mirror/Editor/Weaver/Processors/RpcProcessor.cs:26)
    11. Mirror.Weaver.NetworkBehaviourProcessor:ProcessClientRpc(HashSet`1, MethodDefinition, CustomAttribute) (at Assets/Plugins/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs:782)
    12. Mirror.Weaver.NetworkBehaviourProcessor:ProcessMethods() (at Assets/Plugins/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs:732)
    13. Mirror.Weaver.NetworkBehaviourProcessor:Process() (at Assets/Plugins/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs:47)
    14. Mirror.Weaver.Weaver:ProcessNetworkBehaviourType(TypeDefinition) (at Assets/Plugins/Mirror/Editor/Weaver/Weaver.cs:215)
    15. Mirror.Weaver.Weaver:CheckNetworkBehaviour(TypeDefinition) (at Assets/Plugins/Mirror/Editor/Weaver/Weaver.cs:441)
    16. Mirror.Weaver.Weaver:Weave(String, IEnumerable`1, IAssemblyResolver, String, String, String) (at Assets/Plugins/Mirror/Editor/Weaver/Weaver.cs:577)
    17. Mirror.Weaver.Weaver:WeaveAssemblies(IEnumerable`1, IEnumerable`1, IAssemblyResolver, String, String, String) (at Assets/Plugins/Mirror/Editor/Weaver/Weaver.cs:646)
    18. Mirror.Weaver.Program:Process(String, String, String, String[], String[], Action`1, Action`1) (at Assets/Plugins/Mirror/Editor/Weaver/Program.cs:34)
    19. Mirror.Weaver.CompilationFinishedHook:OnCompilationFinished(String, CompilerMessage[]) (at Assets/Plugins/Mirror/Editor/Weaver/CompilationFinishedHook.cs:129)
    20. UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget)
     
  25. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    That type can't be serialized by Mirror. Are you sure you want to send an Animation Curve over the network?
    Usually they don't change at runtime, you might not need to sync it.
     
  26. CameronBondeSAE

    CameronBondeSAE

    Joined:
    Feb 9, 2017
    Posts:
    2
    Ah, ok. Yeah I guess it's not usually needed. I'm making a 12 Oculus GO's synced VR Cinema app and cave set up. From the server I send a serialisable object with the video clip details of what clip to play to each headset (but the clips themselves are local to each headset).
    This is just for simplicities sake as I'm always changing the master playlist on the server. This way I don't need to sync them. I can also change the playlist on the fly.
    I might have to just send the whole playlist over as JSON and read the curves locally (Anim curves serialise fine to JSON)
    The curves themselves are for motion sickness profiles, so which bit might make people feel like puking :) That way I can draw in the periperal vision, or blank it out for those bits.
     
  27. LeetRooster

    LeetRooster

    Joined:
    Jul 20, 2013
    Posts:
    17
    Hi, I was wondering if it makes sense to compose SyncLists/SyncDictionaries

    I.e. imagine having a SyncDictionary of SyncDictionaries. If you modify a key/value pair in the inner SyncDictionary, is Mirror intelligent enough to only update the one entry in the inner dictionary? OR will it try to serialize the whole inner SyncDictionary, which would be expensive and kind of defeat the purpose?
     
  28. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    Mirror doesn't support composing those types, sorry.
     
  29. stanislavdol

    stanislavdol

    Joined:
    Aug 3, 2013
    Posts:
    269
    Hi, wanted to ask whether using [command]s to send Inputs to the server is the best way to make a fully authoritative server logic using Mirror. Or may be there are benefits of using NetworkMessages or SyncVars instead?
     
    LeetRooster likes this.
  30. LeetRooster

    LeetRooster

    Joined:
    Jul 20, 2013
    Posts:
    17
    Hi, I am trying to understand the situations where you would use a [ClientRPC]/[TargetRPC] over the use of NetworkMessages/NetworkServer.SendToAll(msg).

    Both of these seem to allow you to send an RPC Server->Client. However, it seems that you can write a custom serializer for the message in NetworkServer.SendToAll();

    In my case, I want to send a message which can contain a complex structure (List, Dictionary or Array). Am I forced to use the SendToAll approach? Or can the parameters to the [ClientRpc] contain a the complex structure, and can I somehow specify how that is serialized/deserialzed?

    The other approach I can think of is to send every element in my structure one at a time with a ClientRPC. But I am unsure if there are guarantees that every message is sent, and if they are send in order.
     
  31. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    That depends.
    For example, Minecraft mostly sends inputs to the server. If you press the inventory key then it sends that key to the server. Then the server opens the inventory.

    Other games don't send all the input to the server. You most likely don't need to let the server decide when to open/close the inventory, it's fine if that is client sided. Additionally it would also avoid any delays when opening the inventory, since you don't have to wait for the server's reply.

    Rpcs only work for simple types, e.g. int, string, bool, Array.
    If you need custom serialization then create a new NetworkWriter, write whatever you need into it, then send it via Rpc (by using .ToArray() and sending a byte array) or SendToAll.
     
  32. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    Progress: we have been working on several smaller performance improvements to reduce GC spikes and support more CCU.

    New Showcase: One More Night by Big Red Planet is using Mirror!
     
  33. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    Important Update:
    NetworkReader reimplemented. Benchmark with 1000 readers:

    Before:


    After:


    • Memory usage reduced from 250 KB to 48 bytes.
    • CPU time reduced from 3.82ms to 0.33ms.
     
    hopeful and Paulo_Mattos like this.
  34. unity_Cn_9LZVSq85wBA

    unity_Cn_9LZVSq85wBA

    Joined:
    Apr 30, 2019
    Posts:
    5
    Hi @vis2k, would you please help me to figure it out ?
    I have a function with the tag "Command" , this function is supposed to execute on server ? because when I log isServer in this function I have false

    I have this code attach to player prefab

    Code (CSharp):
    1.  public void SetAuth(NetworkIdentity identity)
    2.    {
    3.        if (isLocalPlayer)
    4.        {
    5.  
    6.            CmdSetAuthority(identity);
    7.        }
    8.    }
    9.  
    10.    public void RemoveAuth(NetworkIdentity identity)
    11.    {
    12.        if (isLocalPlayer)
    13.        {
    14.  
    15.            CmdRemoveAuthority(identity);
    16.        }
    17.    }
    18.  
    19.    [Command]
    20.    void CmdSetAuthority(NetworkIdentity identity)
    21.    {
    22.        var currentOwner = identity.clientAuthorityOwner;
    23.  
    24.        // hasAuthority : true if host, false if client
    25.        Debug.Log("localPlayer" + identity.hasAuthority );
    26.        // Debug.Log("SERVER" + isServer);
    27.        // Debug.Log("owner" + currentOwner);
    28.        // Debug.Log("connect" + connectionToServer);
    29.  
    30.        if (currentOwner == connectionToServer)
    31.        {
    32.            return;
    33.        }
    34.        else
    35.        {
    36.            if (currentOwner == null)
    37.            {
    38.                Debug.Log("OK");
    39.  
    40.                identity.AssignClientAuthority(connectionToServer);
    41.            }
    42.            else
    43.            {
    44.                Debug.Log("Not OK");
    45.            }
    46.        }
    47.    }

    In another script I search all the player prefab in the scene and call the function SetAuth, then I check if the player instance is local then call the Command function, but in the function CmdSetAuthority when I log isServer I received false. And I can't AssignClientAuthority because i'm not in server
     
  35. FoleyX90

    FoleyX90

    Joined:
    Dec 7, 2012
    Posts:
    2
    I can't seem to find anything on Host Migration. Could someone point me to the right place?
     
  36. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    We removed that feature
     
  37. Alexees

    Alexees

    Joined:
    Nov 8, 2017
    Posts:
    188
    @vis2k the reason I am using Mirror is, because it's the better UNET. The reason I was using UNET is because we also support UWP. I now found out that the LLAPITransport script does not support UWP, even though the UNITY LLAPI does. We also use Dissonance voice, which, according to the docs, needs an UDP transport, preferably Ignorance, which does not support UWP...
    Is there even one possible combination that allows me to use Dissonance on UWP?
     
  38. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    Why does the LLAPI transport not work on UWP?
    Is there an error that you encountered? It really just wraps the built in LLAPI, and if that worked for you own UWP then this should work too.
     
  39. Alexees

    Alexees

    Joined:
    Nov 8, 2017
    Posts:
    188
    Your whole LLAPITransport.cs script is wrapped in a directive that avoids its usage as a component on UWP. How does this work with running the NetworkManager on different platforms? Do i need to add it on all other platforms but remove it on UWP? Do I need to use a different script then?
     
  40. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    Feel free to remove the #if and see if that works. We initially added them because LLAPI wasn't found on UWP. Not sure why that works for you with UNET then.
     
  41. Alexees

    Alexees

    Joined:
    Nov 8, 2017
    Posts:
    188
    I will.
    We have an application running that uses the portal and Hololens and is happily networking using UNET for 1,5 years now
     
  42. YuriPetskus

    YuriPetskus

    Joined:
    Jun 22, 2018
    Posts:
    16
    Are there any plans to optimize for mobile?
     
  43. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    Any optimization/fix that we make applies to all platforms :)
     
  44. YuriPetskus

    YuriPetskus

    Joined:
    Jun 22, 2018
    Posts:
    16
    I understand ))
    Is there optimization for cases that only appear on mobile devices?
    For example, when the Internet disappears in subway.
     
  45. Mr-Berni

    Mr-Berni

    Joined:
    Aug 29, 2017
    Posts:
    8
    Hey vis I saw your post on the forums -- Update: NetworkTransform now uses .localPosition and .localRotation for proper VR support  --

    I'm trying to sync up hands and head that are children of the player prefab in ummorpg.

    At this point I'm just trying to get a child cube transform to be tracked across the network and I'm having trouble...

    I know that you cant just sync up the rig through the network (I have been through this with pun in other projects). So i have seperate head and hand object following the pos and rotation of the clients camera rig. I want to send the transform of those 3 gameobjects. They are children of the player prefab in ummorpg. They spawn great but the transforms dont update when I have other users move around.

    Please help! :(
     
  46. stanislavdol

    stanislavdol

    Joined:
    Aug 3, 2013
    Posts:
    269

    Currently TransformBase works only with local authority models, correct?
    I mean, it doesn't seem possible to use it with authoritative server and client-side prediction for lag compensation, since it will overwrite position/rotation of a local player.
    And it only sends position/rotation, there is no server timestamp (only local one) to compare with an old position(not a previous received one, but a position of a local player at a certain moment in time)
     
  47. robochase

    robochase

    Joined:
    Mar 1, 2014
    Posts:
    213
    hey i stepped away from this scene for a while, but i'm glad to see it's still thriving. I've been thinking a lot about networking solutions lately, and I keep coming back to UNET for alot of reasons, so this project is pretty compelling.

    It looks like cecil was moved into the source code huh? so this should effectively be future proofed if/when unity shuts off UNET and cecil? so we can still do command/rpc architecture and cecil injects repetitious code at compile time.

    Also, how easy is it to plug in different low-level transports? i see on the github page a variety of transports are supported, but i'm curious about ones that aren't listed. steamworks is a big one for example. i think the oculus storefront also provides their own networking solution that would be cool to tap into.
     
  48. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,237
    We use a custom Cecil version, which is based on latest Cecil from the original Cecil developer (not Unity's version), with one bug fix applied to it for the Weaver.
     
  49. JLJac

    JLJac

    Joined:
    Feb 18, 2014
    Posts:
    30
    Hello and thank you for making and maintaining this!
    I'm doing my multiplayer "hello world". Got some synchronized little players running around on two builds using the NetWorkManagerHUD default LAN stuff, but now I want to test over the internet. I want to host it on one computer and enter the IP on another, like this stuff from the old NetworkLobby asset:



    Has anyone created a NetworkLobby like that for Mirror? Or is this actually something super obvious and easy that I'm missing?

    Thanks!
     
  50. stanislavdol

    stanislavdol

    Joined:
    Aug 3, 2013
    Posts:
    269
    Also, I just noticed:
    In documentation it says:
    The GetParameterAutoSend and SetParameterAutoSend functions can be used to control which individual animator parameters should be automatically synchronized.

    However, these functions are missing from Network Animator