Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Showcase Mirror - Open Source Networking for Unity

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

  1. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
  2. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    ThreadedTransport early version is ready for testing! :eek::eek::eek:
    https://github.com/MirrorNetworking/Mirror/pull/3582

    ThreadedTransport can be used to elevate any of our Transports out of main thread into a worker thread.
    Starting with Threaded Kcp!

    This frees the main update loop from any transport overhead!
    Also prepares for Encryption Transport, which would be too heavy for main thread.

    2023-08-09 - Threaded Transport V1.png
     
    akuno likes this.
  3. akuno

    akuno

    Joined:
    Dec 14, 2015
    Posts:
    88
  4. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    Coming up soon, before we merge.
     
    akuno likes this.
  5. tuzun

    tuzun

    Joined:
    Apr 19, 2023
    Posts:
    3
    Hello everyone,

    I try to run dedicated server with Simple Network Transport script in Mirror, in these script I enable wss and ssl, however, the server is not starting and only I disable them server starts. I also use cert.pfx and cert.json files which are included ssl certification key files. Do you have any suggestions about this issue?
     
  6. delzhand

    delzhand

    Joined:
    Jul 20, 2012
    Posts:
    26
    I have two commands on my player object:

    Code (CSharp):
    1.     [Command]
    2.     public void CmdTest(string json) {
    3.         Debug.Log("no texture2d");
    4.     }
    5.  
    6.     [Command]
    7.     public void CmdTest2(string json, Texture2D image) {
    8.         Debug.Log("yes texture2d");
    9.     }
    When the commands are invoked from a client back to back, only the version without the texture2d actually generates a log message.

    Code (CSharp):
    1.         Texture2D image = Resources.Load<Texture2D>("Textures/test");
    2.         string tokenJson = GameSystem.Current().GetTokenParams();
    3.         Debug.Log("start tests");
    4.         // Pass along to server
    5.         Player.Self().CmdTest(tokenJson);
    6.         Player.Self().CmdTest2(tokenJson, image);
    7.         Debug.Log("end tests");
    8.  
    According to https://mirror-networking.gitbook.io/docs/manual/guides/data-types, "Mirror supports a number of data types you can use with these, including... Built-in Unity types that are structs under the hood (Color, Sprite, Texture2D, Ray, etc.)"

    So how come the command with a texture2d parameter doesn't work? The test image in only 21.4kb, would that matter?
     
  7. dannypb

    dannypb

    Joined:
    May 8, 2014
    Posts:
    11
    I've been working on a space game for.... years. I am retooling using Mirror. As I set up the game, I want to have one space scene where I load objects as directed from a database on the server side and build the scene. I only want objects from that loaded scene to be visible for the current scene. Other players will be in other versions of the same Unity scene, but I want each player to only see and interact with other players and items in their version of the scene.

    I thought there was an scene or instance ID in the Network Manager, but I see now there is not. Is there a way to manage scenes like this, or do I need to use additive scenes? I would really prefer to just take the scene data from a database and load in the objects for that scene as a player jumps to another system (scene). It is how I've done it in the past.

    thanks for your help.
     
  8. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    Hey everyone, for questions it's best to use #help in our Discord:
    https://discord.gg/xVW4nU4C34
    That's where the team is checking every day. The thread here is mostly just myself.
     
  9. dutarus

    dutarus

    Joined:
    Nov 23, 2013
    Posts:
    4
    I've looked everywhere on this forum and could not find any solution on this particular issue. These errors appeared after I imported 3rd party software called Hathora so I could deploy my multiplayer demo. Would anyone be to help me find a solution? I would be most grateful!:)

    I am using Unity 2022.1.7f1.

    Error code CS0103
     

    Attached Files:

  10. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    Threaded Transport & Threaded KCP are live! :eek::)
    https://github.com/MirrorNetworking/Mirror/pull/3582

    Performance critical games can use this to free KCP overhead from main thread!
    The ThreadedTransport abstraction allows us to do this for any other transport too.

    This also prepares for EncryptedTransport in the future, which would otherwise slow down the main thread!

    As usual, all free & open source!
    2023-08-29 - Threaded Transport, Threaded KCP.png
     
    Last edited: Aug 29, 2023
    akuno, hopeful and mgear like this.
  11. dfaeojl

    dfaeojl

    Joined:
    Sep 5, 2023
    Posts:
    4
    love this package
     
    mischa2k likes this.
  12. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    Quick progress video on Prediction for Mirror.
    - Red lines are the history
    - Green lines are the corrections

    Videos hows stepping through a recorded session for debugging.
    Not release ready yet, just showing our progress.
     
    akuno likes this.
  13. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    Hey everyone, we've received a lot of questions about Godot support in the last 24 hours.
    Mirror will stay on Unity for at least another 5 years due to some larger projects coming out.
    However, we are going to take a look at Godot this week just to see how it would fit.
    You can track updates here: https://discord.gg/uQH5qG4CAZ
    2023-09-13 - Godot.png
     
    GibTreaty, no00ob, Lavendn and 2 others like this.
  14. MihkelT

    MihkelT

    Joined:
    Sep 18, 2014
    Posts:
    21
    Player prefab does not spawn after "Recompile and Continue playing" in Unity

    Unity is set to "Recompile and continue playing". After a recompile I host a session in Mirror using KCP transport. The player prefab is not spawned. This only happens when recompiling. If I stop the player and start it, the player prefab spawns correctly. I'm calling OnApplicationQuit and Awake of both NetworkManager and KCPTransport after recompiling so they should be in their initialized state. But when hosting a game from HUD, it says:

    StartHost: Kcp: RecvBuf = 65536=>7361536 (112x) SendBuf = 65536=>7361536 (112x)

    And then just doesn't spawn the player prefab. Normally player prefab spawns right after that log message. If I exit play mode and start play mode, it spawns correctly. This only fails with "recompile and continue playing" after code changes.
     
  15. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    Recompiling at runtime was never reliable, I wouldn't use it - especially for multiplayer games.
     
  16. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    Made with Mirror: UNLEASHED

    2023-10-18 - 15-00-06@2x_compressed.jpg

    From original devs of World of Warcraft, Kingdoms of Amalur, and EverQuest comes a new family friendly fantasy adventure. Fight against the forces of darkness, explore a world consumed by wild magic, and build a stronghold with your friends to increase your power in a new world.

    Lead by the legendary Brian Birmingham & Irena Pereira, Unleashed is developing their next gen adventure game with Mirror!

    X
    : https://twitter.com/UnleashingGames/
    Web: https://www.unleashedgames.io/

    Super excited to have them on board!
     
    Xaon, jesusluvsyooh, Lavendn and 3 others like this.
  17. akuno

    akuno

    Joined:
    Dec 14, 2015
    Posts:
    88
    That is amazing!
     
    mischa2k likes this.
  18. PixCave

    PixCave

    Joined:
    Oct 4, 2018
    Posts:
    35
    Hello, I'm making a 2D fighting game. I will publish only for WebGL. Does Mirror have WebGL support? If it runs on WebGL, how is its performance? I used Photon PUN2 and Fusion, but their WebGL performance was extremely bad.
     
  19. jesusluvsyooh

    jesusluvsyooh

    Joined:
    Jan 10, 2012
    Posts:
    377
    Yes Mirror works on webgl, many do webgl games, heres one picture of 500 separate connections, all moving around in browser.
     

    Attached Files:

    PixCave likes this.
  20. PixCave

    PixCave

    Joined:
    Oct 4, 2018
    Posts:
    35
    How much latency would there be in a 2D fighting game in WebGL? Photon Fusion had incredible lag. The characters were moving forward by teleporting.
     
  21. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    There is not going to be lag unless your network has lag, or your server is under too high load.
     
    PixCave likes this.
  22. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    Great news: thanks to our friends at Edgegap, Mirror now ships with a built in cloud hosting plugin!
    https://mirror-networking.gitbook.io/docs/hosting/edgegap-hosting-plugin-guide

    Edgegap provides Mirror users with free 0.5 vCPU hosting, so you can launch your game into the cloud with just a few clicks.

    You don't need to deal with dedicated servers, Hetzner, Google Cloud, AWS, Virtual Machines anymore.

    Launch servers directly from Unity!



    Please beware, this is an early preview with lots of rough edges.
    If you encounter issues, please post in our Discord's #edgegap channel.
     
    akuno, Lavendn and hopeful like this.
  23. PixCave

    PixCave

    Joined:
    Oct 4, 2018
    Posts:
    35
    When using Photon Fusion, The reason delay is high on webgl is because webgl(websocket) cannot NAT punch through directly, it needs relay server (STUN server) for NAT (network access translations), so whats happening on webgl with dedicated server build is below:

    client <=> relay (photon cloud) <=> server/host
    and on other platforms (windows/android):
    client <=> server/host

    Is this also the case with Mirror? Will I experience severe lag like in Photon Fusion due to the intervening layers at Mirror?
    Also is there a public test server for testing?
     
    Last edited: Nov 6, 2023
  24. PixCave

    PixCave

    Joined:
    Oct 4, 2018
    Posts:
    35
    I want to test at webgl build. But i have an error as client. How can i fix?
    Unity Editor = Host
    WebGL build browser= Client
    I am clicking to Host (Server + Client) button on Unity Editor. After that, i am clicking Client button but:
    upload_2023-11-6_14-47-0.png
     
  25. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    Yes and no.

    First, you have two ways to host:
    • Dedicated server (client<=>server) - this works with webgl but your server can not be webgl.
    • Player hosted (client<=>relay<=>host) - same as you do right now
    For relay, your latency is high because your player is too far away from the relay.
    For example, if I play from Germany and the next relay is in Spain, that's quite some distance for messages to travel.

    Our friends at Edgegap are solving this by having 400+ relay locations.
    In that case, not only is my nearest relay in Germany, it's also probably in Berlin which is the nearest city where I live.
    In other words, lower latency. So I'd either try this, or use dedicated servers.

    Please ask in the #webtransport channel in our discord, I didn't develop the webgl transport myself.
     
  26. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    jesusluvsyooh and akuno like this.
  27. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    Friday Showcase
    Zooba recently hit 100 million downloads on Google Play.
    Made with Mirror :eek:
    2023-11-17 - 09-53-12@2x.png
     
    jesusluvsyooh and akuno like this.
  28. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
  29. pabuty

    pabuty

    Joined:
    Apr 7, 2022
    Posts:
    24
    Hi,

    When game objects are synced, are their transform synced locally or globally? I'm asking because I want to use gameobject's transform data to communicate bit-level information which may be lost in local-to-global calculations or vice versa. Is it a sensible idea to begin with?

    Cheers
     
    Last edited: Dec 8, 2023
  30. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    First Person Shooter demo is coming soon!

    2023-12-12 - 11-19-44@2x.png

    We are implementing a demo with all the features we've been working on this year:
    • Snapshot Interpolation
    • Lag Compensation
    • Client Side Prediction
    • Two-Click Hosting
    The goal is to build something super snappy that feels very responsive, similar to Quake / Counter-Strike mechanics.

    The demo will live right in the /Examples folder, no separate assets. This way we can iterate on this quickly, and always keep it up to date!

    Release: around January.
     
    Lion_C, Krull, akuno and 1 other person like this.
  31. akuno

    akuno

    Joined:
    Dec 14, 2015
    Posts:
    88
    Hyped!

    Many games today use projectile based shooting (multiple raycasts over time with projectile decay) instead of a single raycast check. Would be amazing if that could be included out of the box ;)
     
    mischa2k and Gamemakers3D like this.
  32. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    Oh I forgot to mention: we'll also test our upcoming Deterministic Physics library with this :)
    Deterministic physics will make prediction (and corrections) significantly easier.
    This is coming to open source netcode, free for all!
     
    Krull, hopeful, akuno and 1 other person like this.
  33. domsigma

    domsigma

    Joined:
    Nov 16, 2023
    Posts:
    1
    I am developing a golf game (not simulator) that is Bullseye mode, rounds have 60 seconds and 6 players only. Round time ends, the scene unloads. Players only need to see the balls that other players shoot, nothing more than it! Players avatars stays at static platforms. Have no camera movement that need to be transmitted, only the UI names above players head and the balls them shoot should be transmitted. Is Mirror the best option to it? It is Android mobile game!
     
  34. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    That's a very simple multiplayer game, you shouldn't encounter any issues.
     
  35. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    Update: we just release a super easy to use Lag Compensator component!

    1. Add it to your Player Object
    2. Call GetComponent<LagCompensator>().RaycastCheck()

    It automatically tracks every player's collider history and automatically estimates how far behind in time the caller is! All you need to do is call one function!

    Documentation:
    https://mirror-networking.gitbook.io/docs/manual/general/lag-compensation



    This will be showcased in the upcoming Mirror Shooter sample (release: March!)
     
    joeconstable97, akuno and mgear like this.
  36. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
  37. akuno

    akuno

    Joined:
    Dec 14, 2015
    Posts:
    88
    Lag compensator works flawlessly! Just adapted it with my ballistics projectile code.
    Super easy to understand and implement. Thanks!

    upload_2024-3-12_22-53-47.png
     
    mischa2k and hopeful like this.
  38. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    2024-03-21 - 15-12-15@2x.png

    MIRROR PREDICTION RELEASED

    We've spent the last 8 months collaborating with a game studio in order to implement a custom Prediction algorithm which is optimized for large physics scenes where few objects are simulated at a time.

    We trade off accuracy for performance, and it seems to work quite well so far!

    => You can try Examples/PredictedBilliards on Github today!
    => It works pretty well in games where the player interacts with a few object at a time!
    => Complex scenes like stacked objects aren't good enough just yet.

    Feel free to try it in your game if the physics are reasonably simple.
    ... Or be safe and wait until we release more complex physics support later this year.

    Please read the full documentation, including the back story about our custom algorithm:
    https://mirror-networking.gitbook.io/docs/manual/general/client-side-prediction

    The Billiards demo that you can try today:
    2024-03-21 - Predicted Billiards Release.png
    And our worst case benchmark in Examples/BenchmarkPrediction:

    We are working on more complex scenes right now:
    2024-03-21 - predicting stacked objects.png
     
    Last edited: Mar 22, 2024
    Lavendn and mgear like this.
  39. Kakr-98

    Kakr-98

    Joined:
    Apr 29, 2020
    Posts:
    36

    Hi, nice work!

    Does this only work with physics prediction? Or it's also able to predict anything, like CCs or custom kinematic controllers, etc?
     
  40. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    Good question, I forgot to add that to the documentation!
    PredictedRigidbody - the component that you just slap on and it works - only works to predict Rigidbodies.
    The Prediction (and correction) algorithms itself are kept generic though - see Prediction.cs.
    Those you could (probably) use for anything, but if you check out PredictedRigidbody.cs you'll notice that it's still a bit of work on top of it to make into an easy to use component.

    But yeah, generally you could use it for other things.
    In practice it'll be some work.
     
  41. Kakr-98

    Kakr-98

    Joined:
    Apr 29, 2020
    Posts:
    36

    To be honest, predicting rigid bodies is not something I ever want to have the cost of in my game, since it can be quite a lot, especially at high ping (>150ms), and somewhat high tickrate. The PhysX integration Unity uses (and PhysX itself) is not designed for rollback/resim. On my machine, it can take more than 10ms just for resim/rollback! That's a massive chunk of the client's frame budget.

    That's why you usually would want to use client-side prediction to only predict kinematic controllers, not rigid bodies. At least until a better physics engine becomes available (like Bepu, once Unity transitions into .NET Core), but at the moment, IMO, it's not practical.
     
    akuno likes this.
  42. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    Yep, this is why we don't call Physics.Simulate() at all.
    We designed this to support large amounts of Rigidbodies in the scene by only rolling back individual objects as needed.
    In other words, we resimulate in C# code, not in PhysX world.
     
  43. Kakr-98

    Kakr-98

    Joined:
    Apr 29, 2020
    Posts:
    36
    Not sure what you mean. Do you mean that you only resimulate when mispredictions occur?

    Since PhysX is non-deterministic, you are gradually desyncing from the server. If you sync up with the server (rollback and resim) each x amount of time after enough divergence happen, this is not different from cpu-spiking every once in a while instead of having consistently low fps.

    Otherwise, there is no way to predict rigidbody collisions without `Simulate`. Physics prediction means predicting the physical simulation.
     
    Last edited: Mar 22, 2024
  44. Kakr-98

    Kakr-98

    Joined:
    Apr 29, 2020
    Posts:
    36
    Reading the full doc, looks like this is not an accurate physical simulation. You accept divergence and you slowly interpolate towards the server state or something like that?

    This is not client-side prediction then. The label is incorrect. CSP strictly, as is known in the industry, means rollback and rsimulation.
     
  45. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    Sharing the initial results for stacked cubes prediction.

    You'll notice that the cubes generally sync really well by default. There are some issues with coming-to-rest where predicted cubes are trying to reach the corrected position but can't, since they are blocked by other cubes. This will be the main issue we want to solve with this demo!

     
  46. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    Sorry, may have worded this wrong.

    Client & Server physics are simulated by Unity by default - and this is still the case here.

    The difference is with rollback & corrections, where the 'industry standard' is to use Physics.Simulate() manually to resimulate after correcting. Instead,

    Mirror does corrections in C# code per-object. That is not as accurate as Physics.Simulate(), but significantly faster.

    For the demos we tried, it works surprisingly well so far.
     
  47. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    Stacked Prediction Update.
    New video shows improvements on objects coming to rest, where if the server object is already sleeping, the client object is now guaranteed to stop attempting to wiggle into place eventually!

    This is not live yet, early preview which will need more testing.

     
    Lavendn likes this.
  48. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    76
    is the mirror on unity asset store one or two?
     
  49. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,350
    What do you mean?