Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Unity Multiplayer Mirror - Networking for Unity (UNET Replacement)

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

  1. antsonthetree

    antsonthetree

    Joined:
    May 15, 2015
    Posts:
    50
    You can repro this with the Move example that is included. Just modify it to create a new controllable object via the SpawnWithClientAuthority function. Doesn't really matter what it is. You will notice that this works perfectly on the host, but the clients are unable to move. The problem seems to be with the SpawnWithClientAuthority function.
     
  2. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    1,193
    Does Mirror work on the HoloLens platform?
     
  3. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    2,877
    Try it!
     
    GameDevCouple_I likes this.
  4. antsonthetree

    antsonthetree

    Joined:
    May 15, 2015
    Posts:
    50
    Attached is an updated version of your Movement example that demonstrates the defect. Basically the new NetworkTransform does not work when it is created via the SpawnWithClientAuthority. Run the example and attach a client. Note the client's pawn does not update, but the server pawn does.
     

    Attached Files:

  5. antsonthetree

    antsonthetree

    Joined:
    May 15, 2015
    Posts:
    50
    I've debugged this and I have it working now for both player and non-player objects. Note that SpawnWithClientAuthority creates non-player objects.

    The lines you need to change are in NetworkTransformBase.cs.
    Line 328 should be
    if (!isServer && hasAuthority)
    The additional check you have for connectionToServer will always fail for non player objects - see unet doc.

    Line 348 should be
    if (!(isLocalPlayer || hasAuthority))
    Note the || and not && - because non player objects with authority need love too.

    Thanks
    Jake
     
  6. shiena

    shiena

    Joined:
    May 19, 2017
    Posts:
    1
    Line 323-328 in NetworkTransformBase.cs
    Code (CSharp):
    1. // no 'else if' since host mode would be both
    2. if (isClient)
    3. {
    4.     // send to server if we have local authority (and aren't the server)
    5.     // -> only if connectionToServer has been initialized yet too
    6.     if (!isServer && hasAuthority && connectionToServer != null)
    The second if statement is isClient and !isServer so it will not work in host mode.
    Why do we need !isServer here?

    I think that together with the plan of @antsonthetree should be the following code.
    Line 328
    Code (CSharp):
    1.     if (hasAuthority)
     
  7. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    261
    Either of you can make an edit on GitHub and submit a PR with a good description of the change.
     
  8. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,224
    Would be good to get Mirror working on 2019 as Unity have thrown out UNET support and left an aftermath of broken assets everywhere, while Mirror doesn't even support it as it has a ton of console errors... Also I know 2019.1a is still in alpha, but it's got less bugs in it than 2018.3 final so yeah please look into soon.

    And Unity can't be bothered to backport a lot fixes or package updates to 2018.2, so basically 2019.1a14 is a less broken version of 2018.3 that has more fixes so I have no interest in using that, and 2018.2 won't get the fixes and package updates that only work in 2019.1
     
  9. antsonthetree

    antsonthetree

    Joined:
    May 15, 2015
    Posts:
    50
    Looks like this issue is already being tracked on github here:
    https://github.com/vis2k/Mirror/issues/273
     
  10. VrTechEx

    VrTechEx

    Joined:
    Aug 4, 2013
    Posts:
    26
    How can you make an RPC Buffered in Mirror? I know it's UNET but any ideas to make it work? Thank you!
     
  11. BiosElement

    BiosElement

    Joined:
    Apr 29, 2013
    Posts:
    10
    I've spent three hours on this so I figure it's time to admit my shame and ask for help.

    I'm testing Mirror for possible replacement of Photon2 in a game where I need players to have access to numerous spawned items from different players, basically as a board game. With Photon2 I'm using a RequestOwnership system which isn't exactly ideal since ownership doesn't matter much but it seems to work. I attempted to hack in an ownership request system or just assign ownership via commands but ran into the usual UNET permissions preventing interacting with non-owned GameObjects. Note my token movement and interactions are handled by the tokens themselves, thus the need for permissions.

    I'd appreciate just a kick in the right direction and thanks for the awesome work with Mirror.
     
  12. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    2,877
    Stress Test Weekend


    Why do you want to make it buffered?

    Join our discord. Someone talked about assigning ownership yesterday, maybe this person can share the code. Also check out our issue tracker, there is a demo about ownership somewhere in an open bug report about networktransform.
     
    BiosElement likes this.
  13. Serinx

    Serinx

    Joined:
    Mar 31, 2014
    Posts:
    486
    Is the authoritative/server-only code in mirror completely hidden from the user? I want to call a backend API from the server-only code with functions such as "Add Item", "Record Win", "Record Loss" etc but I'm worried if the user can decompile the code and work out the functions they might be able to give themselves items and wins.

    Might be a silly question as I'm new to authoritative servers but I'd just like to work out the best way to keep it secure.

    Also, would Mirror be a good option for a smaller scale game with roughly 10 players in a match?
    Or is there another option which would be more fitting.

    Cheers
     
    Last edited: Jan 23, 2019
  14. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    2,877
    If you use IL2CPP then user will only see assembly code. But it's not exactly hidden. Unity 2018.3 has a #if UNITY_SERVER flag that you can use to hide server code from the client.

    Yes, Mirror works for MMO scale projects, so larger ones are no problem either.
     
    Serinx likes this.
  15. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    2,877
    News:
    The Road to 1000 CCU
    - 500 CCU WORST CASE @ 8 CPUs, 32GB RAM


    It's done. Finally, after 3 years of networking hell.

    1000 CCU in a real MMO with players spread across a huge map should be no problem for the server now.

    Big thanks to everyone who contributed to Mirror. It's been a long, difficult journey to get where we are from UNET's initial 20-50 CCU full of errors. Every small contribution, every bug fix and every discussion was needed to get us here. I also apologize for giving everyone such a hard time with pull requests, but I hope that it all makes sense now.

    An open 1000 CCU community test will follow after a few more optimizations and Mirror bug fixes. The new Telepathy version will be released after that test.

    Thanks everyone
     
    pesapower, Novack, tobiass and 3 others like this.
  16. VrTechEx

    VrTechEx

    Joined:
    Aug 4, 2013
    Posts:
    26
    I want all commands and clientrpcs to be buffered when a new player connected into a game. Any ideas ?

    Thank you !
     
  17. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    153
    As someone who's been quietly admiring you guys for a long time and is hesitantly thinking about making networked experiments, where do I sign up to help with those CCU tests?
     
  18. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    2,877
    But why? I don't understand the problem that you are trying to solve.

    Join our discord!
     
  19. antey3064

    antey3064

    Joined:
    Mar 21, 2016
    Posts:
    8
  20. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    2,877
    Recently tested 250 and 500 CCU in uMMORPG successfully. So I am not worried about uSurvival's networking at all right now. uSurvival is meant for games like Dayz/Fortnite, which both only support 100 CCU.

    In other words: if the networking can handle uMMOrpg then uSurvival will always be fine.
     
  21. YuriPetskus

    YuriPetskus

    Joined:
    Jun 22, 2018
    Posts:
    7
    My scene contains 2600 NetworkIdentity objects (game like Minecraft).
    When the client connects, the scene takes more than 10-15 seconds to load and the UI is not responding at this time.

    I started using NetworkProximityChecker. Loading the scene has become faster, but when the player first moves around the scene, the game periodically freezes for 1-2 seconds.

    I think it's because NetworkConnection.HandleBytes () calls ClientScene.OnSpawnPrefab () synchronously.

    Is there a way to spawn scene objects asynchronously?
    Every frame, for example.
     
  22. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    2,877
    Is every voxel a networkidentity? Try making each chunk a NetworkIdentity instead.
    Also try a proximity checker that is grid or chunk based to avoid Spherecasting each time.
     
  23. YuriPetskus

    YuriPetskus

    Joined:
    Jun 22, 2018
    Posts:
    7
    My proximity checker is simple
    Code (CSharp):
    1.         public override bool OnRebuildObservers(HashSet<NetworkConnection> observers, bool initial)
    2.         {
    3.             // only add self as observer if force hidden
    4.             if (forceHidden)
    5.             {
    6.                 // ensure player can still see themself
    7.                 if (connectionToClient != null)
    8.                 {
    9.                     observers.Add(connectionToClient);
    10.                 }
    11.             }
    12.  
    13.             foreach (NetworkConnection conn in NetworkServer.connections.Values)
    14.             {
    15.                 if (conn.visList.Contains(this.netIdentity))
    16.                 {
    17.                     observers.Add(conn);
    18.                     continue;
    19.                 }
    20.  
    21.                 if (conn.playerController == null)
    22.                     continue;
    23.  
    24.                 if (Vector3.Distance(conn.playerController.transform.position, transform.position) < visRange)
    25.                 {
    26.                     observers.Add(conn);
    27.                 }
    28.             }
    29.             // always return true when overwriting OnRebuildObservers so that
    30.             // Mirror knows not to use the built in rebuild method.
    31.             return true;
    32.         }
     
  24. YuriPetskus

    YuriPetskus

    Joined:
    Jun 22, 2018
    Posts:
    7
    It's not voxels basically.
    Each brick is NetworkIdentity and it lies in a free position. There is no chunk actually.

    Something like this
     
  25. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    2,877
    For each networkidentity you are comparing the distance to each player on the server. This is huge amount of computations as soon as you have more than a handful of players.

    The built in proxchecker is probably still faster if you set the cast layers to your player layer.

    I recently added a grid checker to my assets, which is 30x faster than the built in proxchecker again. It simply divides the world into grids and adds all the players in your grid + 8 neighbor grids to observers.
     
  26. antsonthetree

    antsonthetree

    Joined:
    May 15, 2015
    Posts:
    50
    Found a bug - When you spawn an object on the server with a parent, the parent is never sent to the clients. I looked thru the code and I don't see anywhere in NetworkTransformBase where the transform parent is being synced with the clients.

    You can repro this by spawning an object on the server and giving it a parent.
    GameObject theThing = Instantiate(somePrefab, Vector3.zero, Quaternion.identity, someParentTransform);
    NetworkServer.Spawn(theThing);

    Then check the client and you will see theThing does not have a parent.
     
  27. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    2,877
    NetworkIdentities don't work properly if they are parented. They should always be the root GameObject.
     
    Joe-Censored likes this.
  28. antsonthetree

    antsonthetree

    Joined:
    May 15, 2015
    Posts:
    50
    Hello - I am not seeing these shiny new features in the latest Network Manager. Do I need to do something to enable them or is this a "coming soon" feature?
     
  29. VrTechEx

    VrTechEx

    Joined:
    Aug 4, 2013
    Posts:
    26
    I mean when someone already picked an object in the game and then a new player joins in the game. The new player didn't see the previous player picked the object up.
     
  30. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    662
    Drag in the WebSocketTransport into your networkmanager gameobject. The transports are now just components you drag in.
     
  31. Tyrannmisu

    Tyrannmisu

    Joined:
    Oct 23, 2018
    Posts:
    4
    Maybe i am just stupid, but i cannot get networked scene gameobjects to work....
    I just switched from UNet to Mirror and it went mostly fine.

    I happen to have some objects in the scene that have network identities and syncVars. It all works great for the host, but the game objects in question are never enabled for any client.
    The game objects are not parented and it worked fine with UNet.

    I am able to reproduce this behaviour with the basic example, that is included with Mirror.
    Just add an instance of the player prefab into the scene. The additional text will be shown for the host but the GameObject will never be enabled for the client, therefore it will never see the text.

    The log looks like this:
    • DEBUG: TelepathyTransport initialized!
    • WARN: Could not find scene object with sceneid:1431655766
    • ERROR: Spawn scene object not found for 1431655766 SpawnableObjects.Count=1
    • DEBUG: Spawnable: SceneId=1 name=FakePlayer
    Followed by multiple (because it stays disabled):
    WARN: Did not find target for sync message for 1 . Note: this can be completely normal because UDP messages may arrive out of order, so this message might have arrived after a Destroy message.

    I am testing on the same machine by connecting to localhost. Unity version is 2018.2.20f1.
    Mirror is version 1.4 (installed via the asset store)
    I tried to find a solution in this thread and in other places too, but i cant seem to find any.

    Edit:
    I tried to debug the issue on the client and ended up in ClientScene.SpawnSceneObject.
    The actual key for the game object in spawnableObjects is 1 but for some reason it tries to access it with the sceneId 1431655766

    Edit2:
    Okay ... it works if both (host & client) are a build version. If one of them is started via unity it stopps to work. This makes debugging a little hard. :D
     
    Last edited: Feb 6, 2019
  32. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    2,877
    Please open an issue on our github page and tell us exactly how to reproduce it
     
  33. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    261
    Or come visit the Mirror Discord and we can try to see what went wrong.
     
    vis2k likes this.
  34. Yokimato

    Yokimato

    Joined:
    Oct 9, 2012
    Posts:
    8

    I also ran into this issue -- a (very helpful) developer on their discord got me sorted in quick order though. The problem stems from having scenes in the build settings that are disabled causing an index offset problem. Once I simply removed scenes that are not in the build, everything worked as expected.
     
    vis2k likes this.
  35. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    428
    I am working on a single player iphone game where a player plays volleyball against a computer player. I'd like to turn it into a multiplayer ios game.

    I have not made a multiplayer game before, and am still learning about the subject, watching tutorials, reading documentation etc. I couldn't find the answers after looking through the forum and reading about Unet, mirror, and Unity's upcoming projects. Mirror seems really easy to understand and use, but I still can't figure out if it's the right technology for this project.

    Questions:
    1. Is it possible to turn an action physics based iphone game into a multiplayer game using mirror?

    2. I see mention of TCP with latency of 60ms but not sure what type of connection these numbers come from: wireless, LTE, direct connection, peer to peer?

    3. Can a mirror game be hosted by Unity Services, or do you have to setup your own servers?

    4. If there's no matchmaking services in mirror what solutions are available?

    5. Is mirror the wrong technology for this sort of project? If not what is?
     
  36. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    9
    @dansav
    For a 1on1 game you could use a nodeJS server and socket.io, put the two players in a room and send basic events (player/ball movement, etc)
     
  37. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    834
    Another beginner with a simple question, I am in the process of doing a racing game and want to start adding multiplayer support, is Mirror suitable for basic racing game or is it overkill?
     
  38. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    2,877
    Try and see :)
    There is no specific code that would prevent it from working in a racing game.
     
  39. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    2,877
    Progress: Finally fixed the annoying "(Clone)" suffix when spawning objects. This is huge for games that show the name above the entity's head, e.g. MMOs. This way we need no more NetworkNameSync component on monsters. Should offer a significant bandwidth improvement, e.g. when spawning 1000 monsters near a player.

     
  40. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    554
    Hilarious.
     
    Vincenzo and kfng like this.
  41. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,030
    Just starting with Mirror and as I would like to to use UDP I have also added the Ignorance Transport system but when I imported that system I get the error:
    Assets\Mirror\Transports\Ignorance\IgnoranceTransport.cs(225,30): error CS0115: 'IgnoranceTransport.GetConnectionInfo(int, out string)': no suitable method found to override

    Did I mess up the copying? Or do I need certain versions of each system for them to work.

    Also what is the situation regarding NAT punch through with Mirror? Do I need another asset for that?
     
  42. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    662
    That method was added in mirror yesterday, Ignorance needs to be updated with it @Coburn37