Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[RELEASED] Smooth Sync - Smoothly network rigidbodies and transforms while reducing bandwidth

Discussion in 'Assets and Asset Store' started by Fuestrine, Aug 4, 2017.

  1. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @Giantbean
    I don't know what that issue is unfortunately. So I can't really make a good call one way or the other. I'd probably just say that it wouldn't work out of the box for you and you'd still have to deal with parenting in the code yourself.
     
  2. Giantbean

    Giantbean

    Joined:
    Dec 13, 2012
    Posts:
    144
    Thanks.
     
  3. Giantbean

    Giantbean

    Joined:
    Dec 13, 2012
    Posts:
    144
    I just realized its not disappearing but being pushed through the ground when the VR hand grabs it and then spinning and falling away as gravity pulls it out of view. When released it pops back to the point of the VR hand and drops above the ground plain. Also when items like spheres are dropped they roll away much quicker on the server then the client. Is this something Smooth Sync could fix or just some setting I need to change in mirror... or do I need a new custom network script?
     
  4. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    Yes. They would be even on both server and client.

    I'm not sure about your other issue. It doesn't sound familiar so I'm not sure if Smooth Sync would fix it or not.
     
  5. MM47

    MM47

    Joined:
    Sep 7, 2012
    Posts:
    25
    @Fuestrine This is Soldat 2! I'm the original creator of Soldat, now making S2 :D

    The floating point becoming imprecise makes sense however I think there's something else going on here.
    Here are my observations:

    A) setting TimeCorrectionSpeed > 3.0 fixes the issues (however it is jittery)
    (this fixes it because timeChangeMagnitude in adjustOwnerTime() spirals out of control when the desync happens)

    B) replacing Time.RealTimeSinceStartup with a function that returns (40000.0f + Time.RealTimeSinceStartup) - on the server reproduces the desync on client

    C) since Time.RealTimeSinceStartup becomes imprecise I figured I'd replace it with Time.timeSinceLevelLoad (since that should reset on every new level). This reproduces the desync bug immediately for some reason. This leads me to believe there's something else going on here.

    Also 40000.0f is 1 day and I don't think it's enough for the float to become so imprecise.
    I think there's a bug here and it happens whenever the server time differs from the client time by a significant number (so you won't ever see this bug when you test locally, only after the server has been running a few hours).

    EDIT: also I have receivedStatesCounter < SendRate commented out. Although this bug was there before I did that.
     
    Last edited: Aug 20, 2020
  6. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @MM47
    Soldat 2! That's awesome.

    Thanks for all of the detailed information.
    It should make it easy to recreate and fix on my side.

    I'll message you sometime this weekend or early next week and most likely with a fix.

    What Networking System are you using?
     
  7. MM47

    MM47

    Joined:
    Sep 7, 2012
    Posts:
    25
    A fix would be awesome, this is something I tried but cannot fix by myself.
    Networking System - I'm using DarkRift but I based it on SmoothSyncPUN (was very easy to modify).
     
  8. MM47

    MM47

    Joined:
    Sep 7, 2012
    Posts:
    25
    Some more findings:
    timeSinceLevelLoaded is unreliable.
    There is a large discrepancy between editor time and built game time. I'm not sure if this is a new Unity bug or my bug, but this is the first time I noticed this.
    I made a precise measure with System.DateTime.Now and time between FixedUpdate's in game is ~0.17ms (fixedUpdateTime is set to 0.02) and in editor ~0.3ms.
    This seems to make timeSinceLevelLoaded desync very fast. The only reliable time is realTimeSinceStartup. Although now I don't trust it too :).
     
  9. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @MM47
    Thanks for the extra info. I looked into it a bit tonight and I'm seeing the same symptoms. I'm not sure on the cause yet though. I'll poke around some more tomorrow and let you know.
     
  10. Ceylan12

    Ceylan12

    Joined:
    Dec 24, 2016
    Posts:
    113
    Hello, I'm spawning via Manual Instantiation. If I'm using Smooth Sync, Photon View's owner is "Scene" and controlled locally is on for both object. Something's is wrong. Please help me.
    Thank you...
     
    Last edited: Aug 26, 2020
  11. MM47

    MM47

    Joined:
    Sep 7, 2012
    Posts:
    25
    @Fuestrine Might be too early to tell but I think I fixed it. After half a day of the server running the syncing is fine.

    I used my own timer that uses System.DateTime.Now.Ticks to measure intervals between updates + I reset the timer when a new scene loads (to prevent the float being too big).
     
  12. Vauxvogh

    Vauxvogh

    Joined:
    Nov 29, 2017
    Posts:
    10
    @Fuestrine Hey I was talking about when my players die, their body is motionless because they are dead, then they respawn in a new location on the map, it shows the dead body almost like teleport from their location where they died to their new spawn location. How can I stop this? It shouldn't the body should just disappear then reappear in a new spawn point? Should I stop smooth syncing them when they die and re-enable on respawn? It only started doing this when i applied the sooth sync script to the characters and put that in the photon view.
     
  13. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @MM47
    Awesome. It looks like I was wrong to expect more jitter with that being the cause.

    I've actually fixed this issue previously but haven't had time to test it out and get a release out.

    I will fix up my version of this this weekend and send it to you when I'm done. Then you can see if you maybe missed any edge cases at least.

    I also want to look into that first bit of jitter after first spawning and see if I can come up with anything.
     
    MM47 likes this.
  14. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @Ceylan12
    I responded to you via discord already but I wanted to respond here too just in case you didn't see it. :)
     
  15. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @Vauxvogh
    It's still pretty hard to understand exactly, but it sounds like you want to Teleport.

    Use SmoothSync.teleport()

    Teleport will make your object jump to a position instantly.

    If this isn't what you want, are you saying your object is teleporting when it shouldn't be?
     
  16. MM47

    MM47

    Joined:
    Sep 7, 2012
    Posts:
    25
    There are still issues after the server has been running for 1-2 days. They look different than last time but still looks like interpolation issues due to timing. Please send me your fixes, I'll test them out!
     
  17. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @MM47
    The float imprecision with large time fix is done. It has to be dressed up a bit though, so I'll reach out tomorrow and send it your way.
     
  18. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @MM47
    Ran into an issue. Will reach out tomorrow with it.
     
  19. Zebadiah

    Zebadiah

    Joined:
    Apr 6, 2014
    Posts:
    67
    @MM47 I just sent you a message with a link to the new version. It should fix both the jittering in the first seconds of syncing as well as the float precision issues in long running games. Let us know if you run in to any issues with it.
     
    MM47 likes this.
  20. cpasjuste

    cpasjuste

    Joined:
    Apr 2, 2012
    Posts:
    154
    Hi !

    I'm looking closely to your asset :). I did implement my own thing but I'm not 100% satisfied with it, so I may take a look someday at other solutions.

    I have a concern thought, does the "plugin" allow custom property to be sync (like float and vector3)? This would be a big deal to me so I don't have to implement it myself (which would bring me to the starting point, I guess).

    Thanks!
    Cpasjuste.
     
    Last edited: Sep 5, 2020
  21. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @cpasjuste
    Unfortunately Smooth Sync does not work in that way automatically (or easily like how I would like it to be if I were to market this as a feature).

    BUT, it really shouldn't be too hard to add that ability in if you know how to code a bit. Just three spots in the code I believe (send, receive, read). If you end up buying Smooth Sync and want to go that route, let me know and I can point you to the right code sections. Cheers.
     
  22. Litwin

    Litwin

    Joined:
    Aug 15, 2013
    Posts:
    70
    I am interested in buying, but I use another type of networking structure, for example enet-csharp. And I believe there are other people too, would it be possible to add an example for this type of separate client <-> server structure?
     
  23. Mese96

    Mese96

    Joined:
    Jul 23, 2013
    Posts:
    40
    @Zebadiah

    As Mirror again has this callback: "NetworkIdentity.clientAuthorityCallback" the old code should work again right ?
    And this warning could be eliminated: "Smooth ownership changes are broken this release pending an update from Mirror to resurrect the clientAuthorityCallback."

    Will there be an update from SmoothSync to fix this ?
     
  24. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @Litwin
    Sorry but we don't support enet-csharp.
     
  25. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @Mese96
    If the callback works, you should be able to comment
    //NetworkIdentity.clientAuthorityCallback = AssignAuthorityCallback;
    back in now. Then it should work I think. Let me know if it doesn't.

    I'll check it out for the next release. Thanks for the heads up! :)
     
    Last edited: Sep 13, 2020
  26. LastChaos

    LastChaos

    Joined:
    Dec 9, 2013
    Posts:
    39
    Hi, I have a little problem with smooth synchronization of objects from client side. Below is the code that creates an object by the server and throws it. The video clearly shows that on the client side (top), the object is slightly delayed and does not move as smoothly as we would like. Can you help with advice on how to minimize object jitter on the client side? Thanks!

    SmoothSyncMirror.cs: (default parameters)
    Screenshot_1.png

    Code (CSharp):
    1.  
    2. public void SpawnPrefab()
    3. {
    4.     if(isServer) {
    5.         GameObject droppedItem = Instantiate(examplePrefab,
    6.                 cam.position + new Vector3(0,0,0.5f), Random.rotation);
    7.  
    8.         var rigidbody = droppedItem.GetComponent<Rigidbody>();
    9.         if (rigidbody) {
    10.             rigidbody.angularVelocity = Random.rotation.eulerAngles * 150f;
    11.             rigidbody.AddForce(cam.forward * 8f, ForceMode.VelocityChange);
    12.         }
    13.  
    14.         NetworkServer.Spawn(droppedItem);
    15.     }
    16.     else CmdSpawnPrefab();
    17. }
    18.  
    Video: (1/2 speed)
     
    Last edited: Sep 20, 2020
  27. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @LastChaos
    It's hard to tell but it looks like your object may jitter for longer than one second. Smooth Sync deliberately has a bit of a jitter for one second after an object spawns so maybe this is the issue. This is so it can adapt easier to heavy load levels and we were expecting people to be pooling objects as spawning at runtime has a lot of overhead. BUT, we've got a fix for this coming in the next couple weeks.

    Until then, change this line:
    if (receivedStatesCounter < sendRate ||
    into:
    if (receivedStatesCounter < sendRate / 5 ||

    and let me know how it goes. Maybe also just remove that whole part of the conditional too and see how it goes.

    For the delay, try reducing InterpolationBackTime but keep it above 1/SendRate or you will be extrapolating a lot.

    If there's still jitter, I would confirm that only Smooth Sync is updating the positions of non-owned objects.

    Let me know how it goes. :)
     
  28. LastChaos

    LastChaos

    Joined:
    Dec 9, 2013
    Posts:
    39
    @Fuestrine
    I changed these parameters and it became much better. I'll check later for practice how it will work :)
    upload_2020-9-25_12-52-39.png
     
    Last edited: Sep 25, 2020
  29. Giantbean

    Giantbean

    Joined:
    Dec 13, 2012
    Posts:
    144
    Working in VR I have scripts to get authority of an object that's grabbed and Smooth sync set up on objects I pick up to move objects about over the network but grabbed items jitter and wobble about for everyone but the owner. What sort of settings might fix this? I have been playing with Interpellation and send rate but I'm not getting any reduction in the jitter.
     
  30. Tony-Lovell

    Tony-Lovell

    Joined:
    Jul 14, 2014
    Posts:
    127
    I modified your asset a considerable amount on account of my homemade networking and also my need for a "Floating Origin" to accommodate continuous motion across a huge (64-bit space) world. There are still a few bugs, but things are generally working. Confidence is high.

    I use it in two ways. Firstly, I smoothsync FPS characters walking on a ship. This does great, and for good reason -- this is the sort of challenge that informed your design. But I also use it to smooth the motion of the ships these characters walk on, and here the effect is less convincing.

    The ships are physically modelled on the server, and they send their transforms via SmoothSync to the characters on their deck. As you might guess, the smoothness of the rotational motion is critical here, as the players' cameras are being affected directly by these changes in rotation.

    In practice, with my present set-up, I see rather discrete leaps in rotation of the local ship. It might be that the design of this asset is not perfectly aligned with the nature of replicating the motion of a ship on an active ocean swell, but FWIW, this is how I have tried setting it up (I am not using compression). SmoothSync is doing a good job at the positions, but the rotational motion appears sudden and discrete, rather than smooth and continuous.

    A few notes: the low Send Rate of 8Hz is aspirational -- the simulation has ships of 500 tons and up. They're not spry. I also hope to have huge battles.

    If you'd like a video of the resultant motion, I can certainly make one. It's not a horror -- it's just not as good as I will eventually need.

     
  31. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @Giantbean
    What networking system are you using?
    See if you are using one of the systems with "Smooth Authority Changes" under the Miscellaneous tab in the inspector. If so, click it and let me know how that goes.
    If not, you'll have to manually call SmoothSync.clearBuffer() on all of the object's instances if you change the object's network owner. (Other important method tidbits are at the bottom of our Doc's main page here: http://grabblesgame.com/smoothsync/)

    Let me know how it goes.
     
  32. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @Tony-Lovell
    Hmm. I don't see an issue when I rotate the child object in PUN2 example scene provided by Smooth Sync at least.

    Take a look at one of the example scenes and see if this issue persists. If it does, I can take a deep dive into rotation but I don't see anything at first glance.
    If it doesn't persist, maybe you can try looking at the diff between the new code and the version you used and then porting some newer code over. Maybe wait until my newer code gets up on the Asset Store in the next week or so. I do have one general Smooth fix but I'm not sure if that's really the issue here.

    Let me know how it goes.
     
  33. mtompson-com

    mtompson-com

    Joined:
    Feb 4, 2013
    Posts:
    15
    After my player is spawned it is attached (becomes a child) of a moving platform. I have a Smooth Sync Mirror script on the platform and up until now I also had one on the player(s). Problem is when the platform moves at any pace the player lags when viewed from other players.
    I wondered if because these players become children of the platform, should the platform use the 'Child Object to Sync' option? If so, how do I do it, as I'm instantiating the players and will need a few and assign the child?

    many thanks for any ideas...
     
  34. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @mtompson-com
    I think I responded to you on discord already but let me know if that person with the same name and issue wasn't you. :)
     
  35. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,816
    @Fuestrine I've just imported the Mirror package and, using the latest version of Mirror, get the following errors in my project...

    Code (CSharp):
    1. Assets\Smooth Sync\Mirror\Smooth Sync Asset\StateMirror.cs(180,39): error CS0619: 'MessageBase' is obsolete: 'Implement NetworkMessage instead. Use extension methods instead of Serialize/Deserialize, see https://github.com/vis2k/Mirror/pull/2317'
    2.  
    3. Assets\Smooth Sync\Mirror\Smooth Sync Asset\StateMirror.cs(213,30): error CS0115: 'NetworkStateMirror.Serialize(NetworkWriter)': no suitable method found to override
    4.  
    5. Assets\Smooth Sync\Mirror\Smooth Sync Asset\StateMirror.cs(446,30): error CS0115: 'NetworkStateMirror.Deserialize(NetworkReader)': no suitable method found to override
    As per https://github.com/vis2k/Mirror/pull/2317 there was a breaking change released 19 days ago which changes how objects should be serialized and deserialized. Would you be able to ping me when you've released a fix?

    Thanks
     
    Last edited: Oct 25, 2020
  36. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @Meltdown
    I saw they just introduced this in the version they put on the Asset Store today. I'll get a fix out in the next day or so and send you a copy when it's done. Thanks for letting me know.

    Keep in mind that I only keep up with the versions they release on the Asset Store. I can't keep up with each github change they make.
     
    Meltdown likes this.
  37. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,816
    Thank you, I just thought you should be made aware anyway, as I think a lot of people still get Mirror from GitHub.
     
  38. Tony-Lovell

    Tony-Lovell

    Joined:
    Jul 14, 2014
    Posts:
    127
    Hi -- which of the example scenes can work in 2020.1? I notice that UNet cannot.

    tone
     
  39. Tony-Lovell

    Tony-Lovell

    Joined:
    Jul 14, 2014
    Posts:
    127
    One thought on a possible improvement:

    Rather than syncing rotation and position, syncing localRotation and localPosition would be more versatile, as it better covers the case where movement may occur on a moving and rotating platform.

    The change required for this is just in four places or so, I believe, in get/setRotation(), and get/setPosition()
     
  40. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @Tony-Lovell
    Maybe UNet is 100% deprecated these days? I know you used to be able to download it from Unity or something even after they left it out of the engine downloads.
    Mirror, PUN, PUN2 versions should work fine in 2020.1 though.

    I'm not sure how long ago you converted Smooth Sync but there's a variable for that in the inspector if you want it on all the time and it automatically handles that much better these days.
    You are correct that it's just in the get/setPosition and Rotation methods.
    Thanks for the tip though. :)
     
  41. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    Calling all who use Mirror:
    I've got a Mirror fix for the newest Mirror. Private Message me with your invoice number and I'll send you the fix. Otherwise, I'd expect it up on the Asset Store in about 5 business days.
     
  42. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @Meltdown
    I have PMd you the Mirror fix. Thanks for letting me know. :)
     
    Meltdown likes this.
  43. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,816
    @Fuestrine Thanks for the quick update on the Mirror breaking change, its a breath of fresh air to get such great support on an Asset Store asset :eek:

    I wanted to ask a couple of questions about implementing a HUD for SmoothSync, so I can adjust the sliders/values etc in my build at runtime. This current workflow I have of adjusting a value in the editor, building a PC exe, then opening 3 windows to test that change (server, client, client) is painful.

    So I want to create sliders and some textboxes in a HUD, that will update the SmoothSync value for that client.

    My only confusion is around SmoothSync being on the server. Since Mirror uses the same player prefab on client and server.

    My server is authoritative, so players send throttle and steer inputs for my racing game, and the physics resolves on the server, and sends the resulting transforms to the clients.

    I noticed if I remove SmoothSync from the server object, but keep it on the client, the client becomes more jittery. So I take it I always need to keep SmoothSync on both the client and server objects.

    So if I'm creating a HUD with sliders so I can adjust values at runtime, should the slider change the values on both the client and the server, i.e so the SmoothSync params should always be in sync?

    Thanks!
     
    Last edited: Oct 28, 2020
  44. Hukha

    Hukha

    Joined:
    Aug 12, 2013
    Posts:
    61
    Hi!
    We're using DarkRift 2 and we want to use Smooth Sync with it.
    Is there any Script/Extension/Modification made already to not modify everything?
    Thanks!
     
  45. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @Hukha
    There is no drop in solution for Smooth Sync for DarkRift2. You will have to convert it yourself.
    Maybe one of the people on here or discord who has already converted it can help.
     
    Hukha likes this.
  46. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @Meltdown
    Yes, the server and client should have the same variable settings (generally speaking, there's probably plenty of exceptions though).
     
    Meltdown likes this.
  47. Hukha

    Hukha

    Joined:
    Aug 12, 2013
    Posts:
    61
    Sad, you know who has converted it to contact with them?
    Thanks!
     
  48. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @Hukha
    Actually, I don't see anyone who has said they completed or have even started it. I just see people asking if we support it. I must be thinking of people saying they got Forge or some other networking system working.
     
    Hukha likes this.
  49. komrat1988

    komrat1988

    Joined:
    Aug 31, 2020
    Posts:
    1
    Hello. Can you please tell how I can update assets in unity with this fix? Thank you.
     
  50. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    587
    @komrat1988
    Private Message me with your invoice number and I'll send you the fix. It should be "IN" followed by some numbers.