Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Unity 2022.2 is now available as the latest Tech release.
    Dismiss Notice
  3. We are making some changes to the DOTS forums.
    Dismiss Notice
  4. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Unity Multiplayer Mirror - Open Source Networking for Unity

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

  1. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,260
    Remote Statistics released!
    - Add a NetworkStatistics component to your NetworkManager
    - Add a RemoteStatistics component to your player
    - Connect the client to your server
    - Press F11 on the client, log in with the password from remote_statistics.txt

    Additionally, the CCU Test Demo is now available in the Examples folder.
    This ensures that all our tests are easily reproducible by everyone :)

     
    Last edited: Oct 31, 2022
  2. Clashman

    Clashman

    Joined:
    Feb 18, 2019
    Posts:
    51
    Hello !
    I'm using a syncdictionary but it's not sync... I can add things in the dictionary only in server side and on client side, I can't see the added things by the server. Do you know why ?
     
  3. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,260
    CCU tests 2022-10 :eek:
    Instead of releasing Mirror II, we are backporting improvements to current Mirror for free.
    There have been many smaller CPU & Bandwidth improvements during Sept/October.
    Additionally, NetworkTransform V3 is ready for testing.
    • [Rpc]/[Cmd] syncs were moved to the new bidirectional OnSerialize
    • Sending over reliable allows us to apply manual delta compression in OnSerialize.

    We are testing 400 CCU on a 16 vCPU Google Cloud instance.

    Below is a comparison between Mirror II, Mirror before, and Mirror after the latest improvements.
    • 3.7x bandwidth reduction: 7.66 MB/s to 2.04 MB/s
    • 18.7% performance improvement: 32 ms to 26 ms (or 20ms over Telepathy)
    2022-11-01 - 12-20-31@2x.png
    Note that current NetworkTransform is unreliable, while NetworkTransform V3 is reliable.
    It's a trade-off between a small increase in latency, vs. a significant decrease in bandwidth.
    We want to optimize the unreliable NT first, before we decide which one to choose (or offer both).

    Also note that the 18.7% performance improvement is already live on Github either way.

    Disclaimer:
    The numbers apply only to our CCU demo, and the goal is to compare results over time.
    It does not mean every game can support 400+ CCU.
    The CCU demo is publicly available, for everyone to reproduce.
    The test runs on google cloud. Dedicated servers will be 10-20% faster.

    Next steps:
    - Threaded KCP to achieve the same performance as Telepathy (TCP)
    - Try 600/800/1000 CCU
    - Improve unreliable NetworkTransform

    Please consider to support Mirror with your recent bandwidth savings :)

    400 - removed IP.png
     
    Last edited: Nov 1, 2022
  4. Varga87

    Varga87

    Joined:
    Jun 3, 2019
    Posts:
    6
    I have a mirror question. I'm tying to invoke an event from my stateMachine witch is a NetworkBehaviour class to a subscribed State class, but I can't get it to work. Isn't this possible?

    Code (CSharp):
    1. public class StateMachine : NetworkBehaviour {
    2.    public event Action PlayerDetectedEvent;
    3.  
    4.    private void OnTriggerEnter(Collider other)
    5.    {
    6.     Debug.Log("Invoke event");
    7.     PlayerDetectedEvent?.Invoke();
    8.     }
    9. }
    10.  
    11. public class IdleState : State
    12. {
    13.     public override void Enter() {
    14.         stateMachine.PlayerDetectedEvent += OnPlayerDetection;
    15.     }
    16.  
    17.     public override void Exit() {
    18.         stateMachine.PlayerDetectedEvent -= OnPlayerDetection;
    19.     }
    20.  
    21.     private void OnPlayerDetection() {
    22.         Debug.Log("Switch state");
    23.     }
    24. }
    This is what the relevant code looks like. Enter() and Exit() are run when switching in and out of the state (code not featured). I get to the first log "Invoke event", but not "Switch state".
     
  5. Varga87

    Varga87

    Joined:
    Jun 3, 2019
    Posts:
    6
    Never mind I found the error myself. My state was never run correctly!
     
    vis2k likes this.
  6. micpatmc

    micpatmc

    Joined:
    Apr 2, 2020
    Posts:
    1
    upload_2022-11-4_14-3-39.png
    Hello, anytime I have two players on a server, and I go from the lobby to the game scene, it seems that on the client, there is still two players, but on the host, it shows the client has disconnected, and I have this error message every time, any thoughts?
     
  7. SandeepSps

    SandeepSps

    Joined:
    May 26, 2017
    Posts:
    8
    Hi @vis2k ,
    I am struggling with WebGL build. I have it running if I don't use SSL settings, i.e. if I leave "client use wss" and "SSL enabled" as unchecked, but if I check these settings and add my certificate and json file, server starts but client can't connect to it. I am not sure what am I missing here.
    PFA the screenshot of NetworkManager and SimpleWebSockets
     

    Attached Files:

  8. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,260
    Please try our #help channel in discord or asking in the websockets transport channel.
    Never used that one myself :)
     
  9. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,260
    Mirror 2022.10 released on Asset Store (in a few minutes) & GitHub!
    2022-11-09 - 11-14-38@2x.png

    A decent month of improvements.
    Imagine what we could do if we were to work on Mirror full time :)
    https://github.com/sponsors/vis2k
     
  10. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,260
  11. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,260
    Pushed 2022.10 to the Asset Store again today.
    - Fixed Unity 2019/2020 support
    - Fixed WriteString missing EnsureCapacity
     
  12. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,260
    CCU Test: trying the dirty callbacks PR for performance.
    NetworkIdentity.Serialize won't need to iterate all NetworkBehaviours to scan for dirty.
    Instead, NetworkBehaviours register themselves as dirty once they became dirty.

    + 5% reduction in bandwidth since merging Rpc buffers (7.08 MB/s -> 6.75 MB/s)
    + 15% faster world update (26 -> 22ms)

    (this uses NT V2 unreliable)

    Decent incremental improvement.
    Preparing for a larger dirty objects improvement.

    Note that this change is not on master yet.
     
    Last edited: Nov 12, 2022
  13. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,260
    NetworkTransform V3 was merged as a new "NetworkTransformReliable" component.
    Feel free to test it in your projects.
    Keep existing (unreliable) NT if your game requires lowest movement latency.


     
  14. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,142
    Hi,

    Was about to test mirror,
    but got few issues (downloaded zip, copied mirror and scripttemplates to project)
    Errors:
    "Vector3Long.cs(72,26): error CS1002: ; expected"
    "Assets\Mirror\Core\Tools\Vector3Long.cs(77,14): error CS1597: Semicolon after method or accessor block is not valid"

    using 2019.4.19f1
     
  15. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,260
    Fixed, please redownload current master from Github.
    Sorry about that, Unity 2019 does not run at all on my apple silicon mac so I can never try that one.
     
  16. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,142
    Thanks! it fixed that vector3, but new one popped up (i guess it didnt get to compile this far last time)
    Code (CSharp):
    1. Assets\Mirror\Core\NetworkServer.cs(1882,26): error CS0117: 'Time' does not contain a definition for 'timeAsDouble'
    seems that it appeared on 2020.2
    https://docs.unity3d.com/ScriptReference/Time-timeAsDouble.html

    upload_2022-11-17_19-59-36.png

    *replaced those with "NetworkTime.localTime"

    Then few more in:
    Assets\Mirror\Components\RemoteStatistics.cs(186,22): error CS0117: 'Time' does not contain a definition for 'timeAsDouble'
    upload_2022-11-17_19-50-27.png
    and few warnings:
    Assets\Mirror\Core\Tools\Vector3Long.cs(7,19): warning CS0660: 'Vector3Long' defines operator == or operator != but does not override Object.Equals(object o)

    *for testing replaced those with non double Time...

    then few more different errors:
    Assets\Mirror\Tests\Editor\Weaver\WeaverAssembler.cs(20,40): error CS0103: The name 'EditorHelper' does not exist in the current context
    Assets\Mirror\Tests\Editor\Weaver\WeaverTests.cs(50,13): error CS0103: The name 'CompilationFinishedHook' does not exist in the current context
    upload_2022-11-17_20-2-55.png
     
    Last edited: Nov 17, 2022
  17. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,260
    Thanks. Maybe best if you could upgrade to 2020 / 2021 LTS.
    We plan to stay on those for a long time. Wouldn't have upgraded if it wasn't for apple silicon.

    Gonna try to set up 2019 in a virtual machine this weekend.
     
  18. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,142
    Adjusted those manually to non double Time's (and deleted Tests), so got my simple multiplayer test working.

    This project cannot upgrade at the moment, but later using newer version in next.
     
    vis2k likes this.
  19. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,260
    Great news!
    We removed the last remaining client sided KCP allocation!
    The change is already live on GitHub and will be on the Asset Store in 1-2 weeks!
    2022-11-23 - KCP Client allocation free.png
     
    mgear likes this.
  20. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,142
    whats the correct way to sync child transforms? (think player with VR hands for example)

    this one shows something, but adding "network transform child" says its deprecated:
    https://mirror-networking.gitbook.i...pickups-drops-and-child-objects#child-objects

    and cannot use that target field in main network transform,
    since root transform should be synced also (and need more than 1 target for hands, head)

    is there some builtin way or need to make separate script to send position/rotation data?
     
  21. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,260
    You can use as many NetworkTransform components as you like.
    set one .target to itself.
    set another to children, etc.
     
    mgear likes this.
  22. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,142
    Everything works great so far.

    One more question:
    I have player prefab (which is quite complex hierarchy, many components etc)

    When i join as a Client, it works fine.
    When another Client joins, it breaks things (since that player prefab has cameras, scripts etc).

    Is there some easy way of spawning separate prefab for non-local players?

    Currently i disable or destroy those extra components on Start, but it gets messy if anything changes..

    I checked this, and it says: can disable automatic spawning, so maybe somewhere there i can spawn just a simple sphere transfrom that has network transform..(for non local clients joining) ?
    https://mirror-networking.gitbook.io/docs/guides/gameobjects/player-gameobjects

    * or actually spawning separate remote player prefab might not work, since it doesnt have same network component as their matching local player?

    ** switched to simpler player prefab, works better.
     
    Last edited: Dec 2, 2022
  23. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,142
    ".. is currently open in Prefab Edit Mode. Please open the actual scene before launching Mirror."

    Any way to make it automatically exit prefab edit mode, when user presses play? (so can enter playmode easily)


    ps. Docs: cannot copy paste from code snippets? (html uses complex spans?) upload_2022-12-2_14-31-44.png
     
    Last edited: Dec 2, 2022
  24. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    4,260
    Mirror Roadmap updated for 2023:
    https://trello.com/b/fgAE7Tud/mirror-networking

    Summary:

    1. Finish work-in-progress: KCP V2, LocalWorldState, etc.
    2. Minimize open bugs: gives us some breathing room.
    3. Advanced networking (prediction, etc.)

    Let's go :)