Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    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. Baavoz

    Baavoz

    Joined:
    Jul 3, 2016
    Posts:
    3
    I got 28 errors?
     
  2. Rickstrife

    Rickstrife

    Joined:
    Oct 25, 2013
    Posts:
    2
    Hello @Fuestrine

    I am trying to get my player to sync across the network using only the velocity only with 2drigidbody. But it is not working am not sure what I am doing wrong. Any advise would be tremendous. Below is an example of my project.
    (note: am able to get it to work with transform)
    (note: I was able to add PhotonRigidbody2DView on character and as an observed Componet. But I thought this was wrong I felt PUN2 should be able to do this without having to add that componet.)

    Project Context
    - Creating 3 pre-configured Character's on master across network
    - Having all characters do some action (jump)
    - Each Character has a different type of network syncing for us to compare each syncing type. (our old net code sync transform, pun2 transform sync, pun2 velocity sync )


    Test Scene

    upload_2020-4-22_16-11-6.png

    Componets on Character GameObject
    upload_2020-4-22_16-13-0.png
    upload_2020-4-22_16-13-37.png
     
    Last edited: Apr 23, 2020
  3. Gaucho

    Gaucho

    Joined:
    Apr 21, 2013
    Posts:
    3
    Hi there, great product so far! I just encountered a special situation for me:

    I've got a vehicle, in which players can step (they'll become a child of the vehicle, so that they can move inside the vehicle with local movement), and once they step out of it, they become a child of another gameobject (let's say "World").

    How to achieve that with smoothsync? Both possible parents (vehicle and world) do have the smoothsync-script attached to it. Do i have to add a component, once the player is attached to a new parent or will smoothsync handle that for me, as long as the player has a smoothsync component attached?

    I've stripped down my parenting manager to the bare minimum, maybe you can tell me, how to set that up correctly:

    Code (CSharp):
    1. public class PlayerParentingManager : NetworkBehaviour
    2. {
    3.     private bool _isInVehicle;
    4.     private Transform _playersOutOfVehicleParent;
    5.     private Transform _playersInVehicleParent;
    6.  
    7.     void Start()
    8.     {
    9.         _playersOutOfVehicleParent = GameObject.Find("World").transform.Find("PlayersOutside").transform;
    10.         _playersInVehicleParent= GameObject.Find("Vehicle").transform.Find("PlayersInside").transform;
    11.     }
    12.  
    13.     void Update()
    14.     {
    15.         if (isLocalPlayer)
    16.         {
    17.             var collisions = Physics.OverlapSphere(transform.position, 0.5f, LayerMask.GetMask("VehicleCollider"));
    18.  
    19.             if (!collisions.Any() && (_isInVehicle || transform.parent == null))
    20.             {
    21.                 _isInVehicle = false;
    22.                 this.transform.SetParent(_playersOutOfVehicleParent );
    23.             }
    24.  
    25.             if (collisions.Any() && (!_isInVehicle || transform.parent == null))
    26.             {
    27.                 _isInVehicle = true;
    28.                 this.transform.SetParent(_playersInVehicleParent);
    29.             }
    30.         }
    31.     }
    32. }
    So - do players even have to have a smoothSync-Script attached, or only the PlayersOutside and PlayersInside gameobjects with a second one ChildObjectToSync set to the player?

    Specifically asking - do i have to do the parenting on my own on every client by sending a message to them that the parent changed, or will smoothsync take care of that?

    Another question:

    If i have a nested set of Gameobjects, of which i want to sync layer A and C:

    upload_2020-4-23_13-35-22.png

    How to set smoothsync up correctly?
    Adding SmoothSync-Component to A twice (one with none as ChildObjectToSync and another one pointing to B) and then adding one SmoothSync Component to B with ChildObjectToSync set to C?
    or adding three of them to Component A (one with none as ChildObjectToSync, one pointing to B and one pointing to C)?
    Or only adding two to A (one with none as ChildObjectToSync and another one pointing to C directly)?

    Thanks for your reply in advance - looking forward!
     
    Last edited: Apr 23, 2020
  4. phil-harvey

    phil-harvey

    Joined:
    Aug 27, 2014
    Posts:
    65
    Is there going to be a fix for the latest version of Mirror?

    I'm seeing ~35 errors due to changes to NetworkWriter for Mirror.
     
  5. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    453
    @Gaucho
    Hey, I already replied to you in email but wanted to reply here too so people don't think I'm ignoring you. :)

    You will have to change the parent on every networked instance of that object. Smooth Sync should handle it from there. Worst case scenario is you may have to call SmoothSync.Awake on each SmoothSync on the object you are changing the parents/children of.

    For the A, B, C:
    Check out the provided Smooth Sync Mirror Example scene for a similar scenario.
    But if you want to sync just A and C. Put two Smooth Syncs on A and hook one of them up to C using the ChildObjectToSync public variable.
     
  6. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    453
    @phil-harvey
    It works for me with the latest version of Mirror on the Asset Store.
    Unfortunately I can't support each minor change they release on the Mirror github. Let me know if the Asset Store version doesn't work though, those are the major releases that I try to stay compatible with. Thanks for letting me know that a newer version will break it though, I'll also try to keep an eye out for it.
     
    Last edited: Apr 26, 2020
  7. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    453
    @Baavoz
    What networking system are you using?
    When do the errors appear?
     
  8. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    453
    @Rickstrife
    I don't think I've ever had someone try to sync only velocity before.
    Smooth Sync currently doesn't have this functionality.

    If you sync using only velocity, it will be very inaccurate and would only be useful in specific scenarios.
    One reason is that velocity is going to be different between send rates so it's going to not be able to stay at about the same position that well and it will only get more and more off as the game goes on.
    Also, if you get bumped or stopped by something (or stop getting sent velocities because of network lag) it'll just use the newest velocity sent even if it's been a few seconds of that player moving. So having your speed be 50, but being 1 second in the past, the positions are going to be pretty far off.

    Basically, I'd think about syncing position. Let me know if I misunderstood the issue or if you have any other questions.
     
  9. Rickstrife

    Rickstrife

    Joined:
    Oct 25, 2013
    Posts:
    2
    ah okay thank you very much. Appreciate the quick & detailed response.
     
  10. Gaucho

    Gaucho

    Joined:
    Apr 21, 2013
    Posts:
    3
    @Fuestrine Thanks for your reply, and aswell thanks for your emails. Good idea to keep writing here to solve issue aswell for others (if they do face it).

    Unfortunatelly, i still dont get the idea what exactly to do. Just changing the parent does not work, tried it aswell by extending the demo scene.

    Steps to reproduce:

    • Add a 3D called "MovingPlatform" , scale it to 40 / 1 / 40 and move a bit down (so that you can see the parent being moved) and add the attached PlatformMover.cs script to it.
    • Add an empty gameobject called "IdlePlatform".
    • Add to both a NetworkIdentity and a SmoothSync script (leave ChildObjectToSync) empty.
    • Add the ParentingManager.cs script to the player prefab SmoothSyncMirrorPlayerPrefab.prefab
    • Press M to parent to moving platform, press I to parent to idle platform.
    • Once a client hops in, the scales go crazy, so do the positions:
    upload_2020-4-28_21-27-41.png

    upload_2020-4-28_21-33-35.png

    According to the documentation, just changing the parent is wrong, as i'd assume to only have the smooth sync script attached to the top most root element, changing itself and the children.
    I've tried it aswell to add / remove the smooth sync script on every parent change on every client, but this fails asell positioning the objects accordingly. Script to add / remove the smooth sync scripts:

    Code (CSharp):
    1.  
    2. if (transform.parent != null)
    3.         {
    4.             // iterate through all current smooth sync scripts, and remove us from the objects to be synced.
    5.             var currentSyncComponents = transform.parent.GetComponents<SmoothSyncMirror>();
    6.             foreach (var smoothSyncMirror in currentSyncComponents)
    7.             {
    8.                 if (this.gameObject == smoothSyncMirror.childObjectToSync)
    9.                 {
    10.                     Destroy(smoothSyncMirror);
    11.                     break;
    12.                 }
    13.             }
    14.         }
    15.  
    16.         this.transform.SetParent(newParent.transform);
    17.  
    18.         var smoothSync = newParent.AddComponent<SmoothSyncMirror>();
    19.         smoothSync.childObjectToSync = this.gameObject;
    20.         smoothSync.enabled = true;
    21.  
    22.         smoothSync.Awake();
    23.         newParent.GetComponents<SmoothSyncMirror>().First(x => x.childObjectToSync == null).Awake();
    24.  
    What am i missing of the concept of smooth sync here?
     

    Attached Files:

  11. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    453
    @Gaucho
    I'm getting some Mirror error with ParentingManager.cs. I'm not too experienced with Mirror these days so I'm not sure if some setup needs to be done.

    How about instead, can you upload the project with that example scene you described to dropbox or something and send me the link to it in an email?
    Then I'll get a perfect view as to what's happening.
     
    Last edited: Apr 30, 2020
  12. Gaucho

    Gaucho

    Joined:
    Apr 21, 2013
    Posts:
    3
    Thanks for your reply, i've mailed you an example with two different approaches. I was able to get rid of the weird stretching shown in the images, just for all others that are reading this here aswell. It wasn't a bug in smooth sync, rather than a behaviour of unity when reparenting to objects with a scale other than Vector3.one.
     
  13. UDN_5c806b49-d8a0-4f67-a296-c12c91aa7396

    UDN_5c806b49-d8a0-4f67-a296-c12c91aa7396

    Joined:
    Jan 9, 2017
    Posts:
    102
    Is it normal when using Pun2 for your first movement to be jittery? After moving then things are smooth but the very first movement input are jerky. As though smooth sync engines are starting up. Any help?
     
  14. Erdal42

    Erdal42

    Joined:
    Sep 17, 2018
    Posts:
    19
    Just joined the Discord...

    THIS PROJECT IS DEAD.
    DO NOT BUY ...
     
  15. UDN_5c806b49-d8a0-4f67-a296-c12c91aa7396

    UDN_5c806b49-d8a0-4f67-a296-c12c91aa7396

    Joined:
    Jan 9, 2017
    Posts:
    102
  16. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    453
    @UDN_5c806b49-d8a0-4f67-a296-c12c91aa7396
    What a name you have! :)

    Yes, it is normal. In the first second of movement, it is getting used to your relative ping so that it can be as good as possible as soon as possible.
    I tried making it shorter but people were reporting issues. You can change line 2041 in SmoothSyncPun2.cs
    if (receivedStatesCounter < PhotonNetwork.SerializationRate ||
    to
    if (receivedStatesCounter < PhotonNetwork.SerializationRate / 2.0f ||
    or divide by a larger number to make this time period even smaller if you want to try it out.
    In the future, I want to make it so this happens regardless of moving and it just sends for one second when the game is joined so that it is less noticeable but I haven't had time for it yet.

    Let me know if you have any questions.
     
    Last edited: May 14, 2020
    CoyoteFringe likes this.
  17. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    453
    @Erdal42
    We are up to date on all replies here and it's only been two days since the latest post needing a reply here. This project isn't dead. :p I am sorry that we haven't been on discord in some weeks though so I understand how you feel. If it happens again, please feel free to poke us again by email or forums.
     
    CoyoteFringe likes this.
  18. katasteel

    katasteel

    Joined:
    Nov 21, 2014
    Posts:
    207
    It's been a few months now and I haven't seen a new release.
    Any idea when this functionality will be released?
     
  19. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    453
    @katasteel
    Sorry about that, I was trying to release another fix at the same time and then the whole release fell to the side. I'll move this to a high priority and get it out quickly.
     
  20. katasteel

    katasteel

    Joined:
    Nov 21, 2014
    Posts:
    207
    That would be great.
    Thanks a lot.
     
  21. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    453
    @katasteel
    Just submitted it to the Asset Store so I'd expect it in a few days. I'll let you know when it's out.
     
  22. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    423
    where is the change logs ?
     
  23. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    453
    Version 3.26 is now on the Asset Store.

    Change log:
    • Updated to work with latest Mirror release.
    • Performance improvements for Mirror.
    • Added server authority support via Transform Source option.
     
  24. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    453
  25. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    453
    @katasteel @phil-harvey
    Smooth Sync Mirror that works with latest version of Mirror on the Asset Store is now out. Sorry about the wait.
     
  26. jasonofthestorm

    jasonofthestorm

    Joined:
    Aug 22, 2017
    Posts:
    3
    Hi, is there any chance this asset works (or could be easily converted to work) with Normcore? I recently switched from Photon and would like to make sure before purchasing. https://normcore.io/
     
  27. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    453
    @jasonofthestorm
    Smooth Sync would not automatically work out of the box with anything other than the supported networking systems.

    I don't know anything about Normcore but if it can send a byte array across the network and you are an experienced coder, I would think the Photon version of Smooth Sync wouldn't be too crazy to convert to Normcore. But I can't really recommend it as I don't know how difficult it would be. Knowing Photon networking basics would help. Smooth Sync wasn't really made with universality in mind, it was made to be plug and play with the most popular networking systems.
     
  28. keybol23

    keybol23

    Joined:
    Aug 13, 2013
    Posts:
    10
    Can you give a recommended setting for a game like this.
    Game is top down, and players can move in any direction and also jump. Variables to sync is x,y,z of position and y of rotation. What would be your recommended Interpolation Back Time, etc and Extrapolation, Thresholds if any. Here's mine currently but I can see other moving players look like they're teleporting/glitching to where they should be running.
     
  29. Redrag

    Redrag

    Joined:
    Apr 27, 2014
    Posts:
    146
    This is a great asset but apart from just trying every single combination of values I really wish there was some more guidance of settings. I am working at a serialisation rate of 5x /s (is that going to be too low for a fairly slow moving boat?) and i'm getting some hiccups. I believe I should set the interpolation back time as longer than than this so > than 0.2s ? Also - another specific question - how should the rigidbody interpolation be set up?
     
  30. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    453
    @keybol23
    Probably too broad of a question. It all depends on what you are trying to achieve. I'd just start with the default settings. If it's not teleporting/glitching with the default settings, then slowly change the others.
    One big thing to keep in mind is keeping InterpolationBackTime > 1/SendRate (serialization rate in photon land?) or you'll be extrapolating all the time which will cause weirdness.
    Extrapolation and thresholds should probably just remain at default as they won't affect much.
     
  31. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    453
    @Redrag
    InterpolationBackTime should be kept greater than 1/SendRate (pretty sure this is called serialization rate in photon land?). So I'd try increasing it to .3 just to test if that's causing the hiccups or not.
    I don't think 5 sends a second would be too low, it all depends though on what kind of accuracy you are looking for though.

    I've attempted a guide in the past but it has just ended up with me writing out all the comments that come when you mouse over the variables anyway. I'll think about it again though and see if I can approach it a different way.
    I'd say just start by looking at the variables before the first drop down and ignore the rest for now. Default on all of those (except InterpolationBackTime because of your lower send rate) should be good though.

    What settings are you talking about here? Really you can't go too wrong with the default settings if you have a rigidbody you are trying to sync. (except change the InterpolationBackTime to match your send rate).
     
  32. Redrag

    Redrag

    Joined:
    Apr 27, 2014
    Posts:
    146
    Thanks for your answers. The issue is that using Update it seems to have 'surges' and using FixedUpdate it seems to stutter looking like its only updating 10x/s . I have moved InterpolationBackTime to .3 and 0.4 and also reduced the lerp speed. I have also tried various options with using velocity or not. Is it right to use velocity AND position?

    The boat also has buoyancy added locally and this seems to make things worse (although if I remove it its still not 100% smooth.)
     
  33. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    453
    @Redrag
    If you are changing the position locally, that'd add to the stuttering as Smooth Sync is probably trying to set the position at the same time that you are trying to set the position.
    Make sure you are only setting the position on owners (and Smooth Sync will handle setting the position on non-owners) (unless of course you aren't syncing Z position or something then you would be free to set the Z position on every networked instance of the object).

    If you confirm that only Smooth Sync is setting the position (and I'd probably just set WhenToUpdateTransform to Update as that's smoother) and it's still jittery, screenshot me your Smooth Sync settings and your Photon serialization rate and I'll take a look and see if I can find what's going wrong. OR if it's easy for you to send me your project, that's probably the best way for me to get a look at what might be going wrong.
     
  34. shubhank008

    shubhank008

    Joined:
    Apr 3, 2014
    Posts:
    72
    Using this for movement:

    Code (CSharp):
    1. // Update is called once per frame
    2.         void Update()
    3.         {
    4.             if (MultiplayerManager.Instance.checkIfObjectIsMine(this.gameObject) && GetComponent<PlayerController>())
    5.             {
    6.                 thisTransform.Translate(Vector3.forward * Time.deltaTime * speed * speedMultiplier);
    7.                 //GetComponent<Rigidbody>().MovePosition(thisTransform.position + thisTransform.forward * Time.fixedDeltaTime * speed * speedMultiplier);
    8.                 //GetComponent<Rigidbody>().AddRelativeForce(thisTransform.forward * speed * speedMultiplier);
    9.             }
    10.  
    11.         }  

    Speed Boost code (dunno if it affects anything in sync ?)
    Code (CSharp):
    1. internal void speedBoost()
    2.         {
    3.             this.speedMultiplier = this.speedMultiplier * 1.3f;           //Change back to 1 after boost
    4.             //Set engine sound pitch
    5.             engineAudioSource.pitch = engineAudioSource.pitch + ((speed * speedMultiplier) / 10);
    6.             playSpeedBoostEffect();
    7.         }
    8.         internal void speedBoostReset()
    9.         {
    10.             this.speedMultiplier = this.speedMultiplier / 1.3f;           //Change back to 1 after boost
    11.             //Set engine sound pitch
    12.             engineAudioSource.pitch = engineAudioSource.pitch - ((speed * speedMultiplier) / 10);
    13.             stopSpeedBoostEffect();
    14.  
    15.         }
    Sync settings
    Unity_oqo761PDxS.png



    Yet the result
    KRn3oEhUOs.gif


    I do not get why I am having this kind of result I have been trying to solve this mystery since a week now tried pun transform view, classic view, self ccreated lag correction and compensation solutions via punobservable, PUN Simple Network Sync yet everything similar problem where even if I bring one car close to another in 1 window, its still away from it in 2nd window

    Detailed code/problem thread - https://forum.unity.com/threads/photon-pun2-non-rigidbody-lag-compensation-and-jittery-cars.912779/
     
  35. shubhank008

    shubhank008

    Joined:
    Apr 3, 2014
    Posts:
    72
    I have also PMed you my project zip file to take a better look if you want to as I am now just clueless as a duck
     
  36. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    453
    @shubhank008
    Hi. I responded to you on discord already but I'm going to copy/paste my response here so others can see too. Let me know if you have more questions. :)

    So depending on your speed, things are just never going to line up perfectly. Check out a game like Fortnite and run next to someone and look at the two screens. It doesn't line up.
    [10:23 AM]
    You'll also see some jitter too. It's hard to notice in a real game and barely affects gameplay but even Fortnite has these issues. Most of networking is just hiding the fact that there's a limitation on how accurate two computers can be because of network lag.(edited)
    [10:24 AM]
    Even two instances of your game on the same computer, you have to tell it to send position, wait a frame for it to actually send, receive it on another frame, then apply it on the next frame. (Maybe one less frame, I forget the exact steps) I forget the math right now, but at like 60mph, you are still going to be "meters" (units) apart.(edited)
    [10:25 AM]
    You'd have to be constantly extrapolating into the future for it to line up, which then produces a whole host of other issues.
    [10:26 AM]
    As far as using Smooth Sync to line up better, try lowing InterpolationBackTime but try to keep it over 1/send rate(send rate is serialization rate in photon land?) or else you will be extrapolating a lot which may cause jitter.(edited)
    [10:27 AM]
    InterpolationBackTime specifically puts objects that amount of time in the past to buffer against lag spikes. So you could lag out for .1 seconds (the default InterpolationBackTime value) and still have buttery smooth super acurate representation of where the other player went.(edited)
    [10:31 AM]
    One thing I implemented for cars and following jitter in Smooth Sync is "Use Velocity Driven Syncing" under the Miscellaneous section of Smooth Sync settings. This will make it smoother, but it WILL be less accurate. Everything in networking is a trade off and it's just never going to be perfect because of the asynchronous limitations of networking.
     
  37. Vincent13122

    Vincent13122

    Joined:
    Oct 26, 2014
    Posts:
    73
    Hi there, I was wondering how well this asset would sync an entire ragdoll (All of its limbs individually). Would that work well?
    I am using an active ragdoll system so I can't just sync animations - but if I disable the animator on all non-owners and just have the owner sync all bone transforms, could that work?
     
  38. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    453
    @Vincent13122
    I would think syncing each limb individually would be a waste of networking resources. Depending on how important it is to your game, I would just sync the parent and let the limbs flop around.

    But if it's important to sync each limb in your game, I don't see why Smooth Sync wouldn't be able to sync your limbs. I just worry you are trying to sync hundreds of objects which no networking would handle that well. It's not a Smooth Sync limitation though, just a limitation of whatever networking system you are using. In fact I would think Smooth Sync would help with syncing them better because we offer a lot of ways to reduce the networking resources that are used for transformation syncing while still remaining buttery smooth.

    Let me know if you have any questions.
     
  39. Vincent13122

    Vincent13122

    Joined:
    Oct 26, 2014
    Posts:
    73
    Thanks a lot, I'll buy it!
     
unityunity