Search Unity

Showcase Mirror - Open Source Networking for Unity

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

  1. timsp

    timsp

    Joined:
    Jul 6, 2018
    Posts:
    3
    Hello, I'm converting a working UNET project to Mirror and am having trouble loading scenes when the built exe is the client
    I can load scenes between two editor sessions and can load a scene when the built exe is the host and the editor is the client. However, The load fails on the client when the editor is host and the exe is client.
    I have the scene-to-be-loaded in the build list. Is there some other step I have to take to register a scene as loadable?
    Unity 2018.3.12f1, Mirror master (b4c9c6f). Also tried with asset store version.

    /edit - exe host and exe client works, so this is a minor issue that only affects the case where exe is client and editor is host.

    /edit again - we are having a similar issue when running two editors on two machines, which is needed for our applications. We were able to do this with UNET. I'm guessing the hash/id for the scenes is different, though the data is identical. Is this a known issue? Any pointers to look in the code to see how/where the id is generated? thanks

    /possible resolution - We had not been using Online scene with UNET, and had nearly all our gameobjects in our 'main' scene. I realized that existing NetworkIdentity components in this Main scene were not getting assigned networkids on the clients. UNET used to correctly give existing these components ids, Mirror does not appear to.
    Workaround is a 'main' scene with only the NetworkManager and make our old main scene the online scene (with the NetworkManager removed) With this change, networkIdentities in the online scene are getting netids.

    Partial log in spoiler:
    Spawn scene object not found for D859ACD4 SpawnableObjects.Count=0
    UnityEngine.Debug:LogError(Object)
    Mirror.ClientScene:OnSpawnSceneObject(NetworkConnection, SpawnSceneObjectMessage) (at Assets/Mirror/Runtime/ClientScene.cs:405)
    Mirror.<>c__DisplayClass6_0`1:<MessageHandler>b__0(NetworkMessage) (at Assets/Mirror/Runtime/MessagePacker.cs:128)
    Mirror.NetworkConnection:InvokeHandler(Int32, NetworkReader) (at Assets/Mirror/Runtime/NetworkConnection.cs:205)
    Mirror.NetworkConnection:TransportReceive(Byte[]) (at Assets/Mirror/Runtime/NetworkConnection.cs:236)
    Mirror.NetworkClient:OnDataReceived(Byte[]) (at Assets/Mirror/Runtime/NetworkClient.cs:126)
    UnityEngine.Events.UnityEvent`1:Invoke(Byte[])
    Mirror.TelepathyTransport:processClientMessage() (at Assets/Mirror/Runtime/Transport/TelepathyTransport.cs:69)
    Mirror.TelepathyTransport:LateUpdate() (at Assets/Mirror/Runtime/Transport/TelepathyTransport.cs:96)
     
    Last edited: Apr 18, 2019
  2. Deleted User

    Deleted User

    Guest

    @vis2k you mentioned this some time ago. How would you go about it? copy paste the component from the Unity Bitbucket and convert it?
     
  3. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Check out the UDP transports that work with Mirror. LiteNetLib offers it, ENET maybe too
     
  4. honzapat

    honzapat

    Joined:
    Oct 3, 2015
    Posts:
    18
    Scene loading does not work in the newest version
    Editor:2018.3.11f1
    Mirror:Newest to this date on assetstore
    NetworkManager wont switch to online scene from offline scene and vica versa and completely scene managin seems F***edup.
     
  5. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    News: POPULATION: ONE by BigBoxVR added to our Showcase!


    Thanks to the BigBoxVR guys for trusting us with their networking.
    Makes us insanely happy to see Mirror being used in action!
     
    Hypertectonic, HeadClot88 and hopeful like this.
  6. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    368
    Cannot reproduce...here's what I tried:

    Starting with the Additive Scenes example, I created an offline scene, moved the Additive Network Manager to that scene, and moved the subscene loading code from OnStartServer to OnServerSceneChanged so it would only run in the MainScene, added the offline scene as first in the build settings, and assigned the offline and main scenes to the Additive Network Manager, built and run. Start Host in editor, built app as client. Both switch to the game scene and offline scene correctly as expected when clicking the appropriate start and stop buttons in the HUD.

    Drop by our Discord and we'll try to help figure out where you went wrong.
     
  7. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    368
    This was resolved in Discord. User had a Network Manager in all scenes instead of just the first (offline) scene.
     
    mischa2k likes this.
  8. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,982
    How would I go about implementing network discovery across LAN? Trying to get players to auto find each other + be visible in a lobby list if they are on the same network
     
  9. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Check out our UDP transports, most of them support network discovery!
     
    MadeFromPolygons likes this.
  10. Lork

    Lork

    Joined:
    Jul 12, 2013
    Posts:
    79
    Is there a universal way to tell whether code is running on a client or the server? The isServer and isClient properties of NetworkBehaviour are the only ones I've found, but they require access to a specific instance of a NetworkBehaviour and seem to get set very late, which makes them not very useful for setting things up.
     
  11. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    368
    NetworkServer.active
    NetworkClient.active
     
  12. Lork

    Lork

    Joined:
    Jul 12, 2013
    Posts:
    79
    Thanks.

    Is there a recommended way to determine when all clients are "ready? ie. player objects are registered with the server, all network gameobjects have been spawned and their SyncVars have been initialized.

    Right now I'm having one of my NetworkBehaviours send a command when a certain SyncVar changes from its default value, but I suspect there's a better way to do it.
     
  13. Katori

    Katori

    Joined:
    Nov 30, 2009
    Posts:
    60
    I just released RocketSockets, a WebSockets transport for Mirror that runs totally outside of Unity.

    The key difference in RocketSockets and existing transports is not only that it runs outside of Unity, but it also allows you to run and manage multiple WebSockets servers from a single server binary, eliminating the overhead of running multiple local and remote connections in multiple binary instances. I've also seen reduced CPU and RAM on the Unity side in my tests with my game, since Unity isn't doing the networking work anymore. And of course, it supports unlimited CCU - as many as your hardware can handle, and I'm pretty confident it can handle a lot more with this than with any other WebSockets solution that runs inside Unity.

    In celebration of and exclusively for the Unity forums I have two 10% off coupon codes for Unity forum users. Please reply or PM me if you use them so I can strike them through.
    UNITYFORUM01
    UNITYFORUM02

    Feel free to let me know here or in the Mirror Discord if you have any feedback about RS, I have some great stuff coming for it.
     
  14. ry00n

    ry00n

    Joined:
    Mar 3, 2018
    Posts:
    6
    I've been struggling with finding answers to a couple things (maybe more UNET related in general) and was hoping someone might be able to chime in:

    1) How does "Server tick rate" under "Network Manager" script relate to "Network Sync Interval" that is available on individual scripts that have SyncVars ?

    My current assumption is that the sync interval of individual scripts can be slower than but not faster than the server tick rate but I'd like to confirm that

    2) SyncVars only update on change, correct?
    I believe that's what I gathered from this old UNET blog https://blogs.unity3d.com/2014/05/29/unet-syncvar/

    I just want to make sure I'm not using up tons of bandwidth using a whole bunch of SyncVars for what basically amounts to some initialization. For SyncVars that don't really get used again or very sporadically.

    3) For sending (fairly) large amounts of data- Are multiple SyncVars fairly well optimized?
    Suppose I have a handful of various data types like booleans, ints, gameObjects and colors I need to sync up between players. Are separate SyncVars wasteful for that?

    Or would I get any benefit from looking into SyncLists, or Serializing and Deserializing manually?

    4) Are there any examples out there of using other transport layers? (specifically UDP based Ignorance or LiteNetLib4Mirror?)

    Specifically I'm curious about channel configuration (reliable vs unreliable) and management.

    I plan to start digging through the source code so I can answer some of these questions myself but thought I would reach out

    I've already been able to play online with friends so I'm miles ahead of where I would be without Mirror! Although I am consuming more bandwidth than I expected which is why I'm starting to dig deeper into this stuff.
     
    HeadClot88 likes this.
  15. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    768
    The Server tick rate simply sets the frame rate of headless servers. That is all. Ideally we would not mess with that at all, but the default behavior from unity is just asinine and causes headless servers to suck up a lot of CPU doing nothing.

    The Network Sync Interval determines how often syncvars are synchronized. You can change synvars 100 times in a short amount of time, but Mirror will only synchronize the last value when the interval expires.

    The server tick rate determines how often the Update() function is called in the server, we can't synchronize variables any faster than that, so the server tick rate imposes a lower limit for the sync interval.

    Yes. SyncVars only synchronize when they change. If an object does not change, no message is sent.

    Syncvars are highly optimized for this. Suppose you have 30 syncvar variables in a component. Suppose you change 5 of them. When the sync interval is met, Mirror will generate one message with the 5 variables that changed plus a small bit mask.

    Having separate syncvars allows mirror to batch them together and only synchronize the ones that changed.

    https://github.com/SoftwareGuy/Ignorance/tree/master/Assets/Demo

    We could really use some sort of profiling tool. It is hard to determine what consumes bandwidth.
     
    Nattress likes this.
  16. merckerrobert

    merckerrobert

    Joined:
    Jun 22, 2017
    Posts:
    4

    Does this allow the use of networkidentity components to be on dontdestroyonload game objects?
     
  17. Deleted User

    Deleted User

    Guest

    @vis2k How do I get help on "Could not find scene object with sceneid" issues? In Discord Help channel nobody answered my question.
    I do have a little problem with I guess different scene setups on server and client. My server needs to only load 3 scenes while clients additionally load environments. Now I get "Could not find scene object with sceneid" warnings. Do I have to make sure particular scenes are listed in a certain order, a particular scene needs to be set active, or what do I have to check to get this working alright? My setup comes from UNET and it worked there.
     
  18. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    If you think you found a bug then please create a small project where we can reproduce it
     
  19. Deleted User

    Deleted User

    Guest

    I don't think I did. I guess it's just something with my setup, but I have no idea how to validate it. How do I go from these errors to why are they not found?
    I'm not even sure what gameobjects they are.
     
    Last edited by a moderator: May 14, 2019
  20. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Can you explain your problem with as much detail as possible? Ideally a video
     
  21. merckerrobert

    merckerrobert

    Joined:
    Jun 22, 2017
    Posts:
    4
    @Alexees are you using networkidentity with don't destroy on load objects, that causes issues with mine.

    @vis2k does the most recent mirror release support networkidentity with dontdestroyonload objects?
     
  22. Deleted User

    Deleted User

    Guest

    Nevermind for now. I was using the AdditiveNetworkManager without loading additively on clients cause I thought that's what it would automatically do. And now need to delay the ClientScene ready until that is done because of the network calls coming in too early for the scene gameobjects to be available, which caused the problem.
     
  23. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Progress Update: the giant wave of features/modifications has finally slowed down, so expect fewer breaking changes in the next couple of weeks. We are focusing on open issues and minor improvements now!

    Try and let us know :)
    Scene switching is very complex. We got it to work reasonably well now, but there might still be some edge cases left.
     
    HeadClot88 likes this.
  24. Deleted User

    Deleted User

    Guest

    I would never do that, it sounds like a really bad idea.
     
  25. Andy3D

    Andy3D

    Joined:
    Jan 31, 2015
    Posts:
    42
    Hope this is the right place to ask. Im developing an app for Oculus Go using Unity, and need some way of managing options within the app from an external Android tablet. Basically, to hide/show scene buttons in the lobby, start scenes up, and send a couple of setup variables across to the headset, record some basic session info from the headset)
    Ideally, it could be two versions of the same app - with the admin app being the server, and the headset being the client. Then having the admin be able to show/hide buttons, whilst the headset can just click whats been enabled.
    Anyone have any idea on which of the many networking solutions would be a good fit?
    Thanks a lot
     
  26. merckerrobert

    merckerrobert

    Joined:
    Jun 22, 2017
    Posts:
    4
    @vis2k turns out mirror still doesn't support using DontDestroyOnLoad and NetworkIdentity, but if someone wanted to make mirror support it they would need to make it so the network identity knows its a dontDestroyOnLoad and have the person give it a unique string for hashing. Also the networkscenepostprocess.cs would need to allow for dontDestroyOnLoad objects to be found in resources. However there is still the issue of returning to the original scene with said object.
     
  27. xxUnlinkxx

    xxUnlinkxx

    Joined:
    May 10, 2019
    Posts:
    1
    Can someone help? for some reason when I try to use OnStartClient() it says this in the console:
    Exception in OnStartClient:Object reference not set to an instance of an object at Mirror.Examples.NetworkLobby.NetworkLobbyPlayerExt.OnStartClient () [0x00065]

    NetworkLobbyPlayerExt.cs:27
     
  28. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Takek a look at NetworkLobbyPlayerExt.cs:27 - there is probably a null value where it shouldn't.
     
  29. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    I'm pretty new to networking and am stumbling across the terror that is the uNet situation. Mirror looks like an awesome fix for a 2yr old project that's heavily invested in MonoBehaviour. The only thing is it's using matchmaking to set up its online games. Will Mirror work with matchmaking?
     
  30. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    We don't use any of the Unity services. I am not sure if they are even supported anymore.
    But you can create your own matchmaking if needed.
     
  31. stanislavdol

    stanislavdol

    Joined:
    Aug 3, 2013
    Posts:
    282
    Hi, first of all, this is an amazing project, finally, a relatively easy way to get an authoritative server with authoritative game logic.

    Unfortunately, I am not very familiar with server hardware requirements.
    In your uSurvival test you used:

    Xeon W-2145 8 Cores x 3.7 GHz
    128 GB DDR3
    240 GB SSD, 6GB/s
    Ubuntu 16.04 LTS

    Considering that it was the worst case scenario, is it safe to assume that it should be sufficient for 300-400 CCU?
    But for a smaller,room based game(matchmaking is not an issue) with let's say under 16 players per room, what setup should I look for? Will vps be sufficient, considering that server runs a unity instance and has to make some physics calculations?
    Is there any practical way to estimate that?
    Also, is there a significant performance advantage of using ubuntu instead of windows?
    Thank you.
     
    mischa2k likes this.
  32. mischa2k

    mischa2k

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

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    368
    Server Build is a console app in Windows...works great.
     
    mischa2k likes this.
  34. LeetRooster

    LeetRooster

    Joined:
    Jul 20, 2013
    Posts:
    18
    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
     
  35. mischa2k

    mischa2k

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

    stanislavdol

    Joined:
    Aug 3, 2013
    Posts:
    282
    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?
     
  37. AlexaRebecca

    AlexaRebecca

    Joined:
    Dec 14, 2018
    Posts:
    26
    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
     
  38. mischa2k

    mischa2k

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

    Oscar-Tsang

    Joined:
    Nov 7, 2012
    Posts:
    84
    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.
  40. LeetRooster

    LeetRooster

    Joined:
    Jul 20, 2013
    Posts:
    18
    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
     
  41. LeetRooster

    LeetRooster

    Joined:
    Jul 20, 2013
    Posts:
    18
    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
  42. mischa2k

    mischa2k

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

    mischa2k

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

    MonkeyS_Finger

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

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Sure
     
  46. tapticc

    tapticc

    Joined:
    Jan 16, 2014
    Posts:
    379
    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.
  47. stanislavdol

    stanislavdol

    Joined:
    Aug 3, 2013
    Posts:
    282
    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
     
  48. LeetRooster

    LeetRooster

    Joined:
    Jul 20, 2013
    Posts:
    18
    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?
     
  49. mischa2k

    mischa2k

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