Search Unity

[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:
    590
    @Paradoks
    It will sync any object even if you don't have a rigidbody on it. Just place the SmoothSync script onto the parent object.

    Let me know if I misunderstood the question or if you have any problems. Cheers. :)
     
  2. roger-ramos

    roger-ramos

    Joined:
    May 16, 2015
    Posts:
    3
    Hello Fuestrine,

    I recently bought the smooth sync component, is working as expected but some times is throwing some errors, SmoothSync Error1.png
    Thank you.
     
  3. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @roger-ramos
    That shouldn't be causing any problems. I thought I fixed that in the last update but maybe not. I'll be pushing a new build this weekend anyway. Thanks for letting me know.

    To stop seeing red immediately, you can change that line to:

    Code (CSharp):
    1. if (networkState != null && networkState.smoothSync != null && !networkState.smoothSync.hasAuthority)
     
  4. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    436
    @Fuestrine
    In fact, from now, i used a simple script that was taking position and rotation, from server into a syncvar, and updated the client position with a syncVarHook, it works pretty well, but i was afraid to take a too much bandwith so i bought your tool.
    Replaced my script by yours, it dont sync position or rotation.
    Nnote that i did not touch anything from the default setting to work with my character controller.

    Edit:
    Its like the client side react like it is the server side, so there is a conflict.

    Edit: When i try your script with a simple cube, wich is allready in the scene at startup it works well, but my character is spawned by a GameManager with server authority, client send wanted position to server, server move and send position to client, in a simple authoritative way.
     
    Last edited: Dec 8, 2017
  5. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @Paradoks
    I don't get this problem in the example scene. My guess is that you aren't setting authority.

    If you uncheck localPlayerAuthority, the server will be the owner automatically. If you want the client to be the owner, you will set the authority with GetComponent<NetworkIdentity>().AssignClientAuthority(conn);

    If you are still having problems, sending me a small project with the problem (preferably the example scene modified) or sending me exact steps to replicate the issue will help a lot.

    What does your spawn code look like?
     
    Last edited: Dec 8, 2017
  6. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    436
    Edit: It works fine, i had a var conflicting - thx !
     
    Last edited: Dec 9, 2017
  7. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @Paradoks
    If you have local player authority set to true, then the client will be the owner. Moving the object on the server will not change the position on all of the objects since it is not the owner. The non-owner objects get updated from the owner object.

    If you uncheck localPlayerAuthority, the server will be the owner automatically.

    Let me know if you still have problems.
     
  8. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    436
    Its works, but now i would like to avoid having this little slide at the end of the movement when the server stops.
    What would be the best way for that ?
     
  9. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @Paradoks
    Increase received movement threshold. I think your problem is that it's extrapolating and then stopping instantly, so the non owner thinks it's a bit further than it actually is so it corrects back to the real position.

    You can also slow your character down instead of instantly stopping them to help this problem if you don't like what increasing received movement threshold does.
     
  10. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    436
    in fact it's the opposite, the client slide to reach the server position after the server has stoped.
     
  11. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @Paradoks
    Yes, since the server is the owner, the client (non-owner) would be sliding to the server (owner) position. Let me know if you have any problems with the solutions I said above.
     
    Last edited: Dec 9, 2017
  12. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    436
    Could it be possible to not use movement threshold ?
    I mean, i got a lot of units running around, and every fixed frame you check for distance wich in my case is performance consuming.
    Could you make something like:
    if mouvement Threshold == 0 then check if last position == actual position
    or
    update anyways every X seconds

    thx, otherwise it works well
     
  13. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @Paradoks
    Sure, just take out that check and always update it. Code provided below. It's not needed to fix your sliding problem either. You can also slow your character down instead of instantly stopping them to help the sliding problem.

    I'll go back in and look at bypassing the distance checks for the default received threshold or maybe I'll make a checkbox for the next update I put out though, it's a great idea. Thanks for the feedback.

    Code (CSharp):
    1. bool changedDistanceEnough = false;
    2.                 float distance = Vector3.Distance(getPosition(), targetState.position);
    3.                 if (distance > receivedMovementThreshold)
    4.                 {
    5.                     changedDistanceEnough = true;
    6.                 }
    7.  
    8.  
    9. CHANGE THE ABOVE TO:
    10.  
    11.  
    12. bool changedDistanceEnough = true;
    13.                 //float distance = Vector3.Distance(getPosition(), targetState.position);
    14.                 //if (distance > receivedMovementThreshold)
    15.                 //{
    16.                 //    changedDistanceEnough = true;
    17.                 //}
     
    Last edited: Dec 10, 2017
  14. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    436
    great!
    Dont forget to put the:
    if( serverPos == clientPos)
    so even if he dont check for distance, he will not update non-moving neither.
    looking forward for the next update then.
     
  15. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Wrestling with an issue to do with syncing non movement or position properties.

    Is there a way to have SmoothSync synchronize properties of Child Objects other than movement or position?

    I need to synchronize a Boolean and String variable associated with a Child Object.
     
  16. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @eco_bach
    Replied to your email you sent me.
     
  17. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @Stabbarey
    If it's happening locally but that information isn't getting shared over the network, one way is to call Command and RPC to send the damage around to the different computers.

    More information here: https://docs.unity3d.com/Manual/UNetActions.html

    Let me know if I misunderstood your problem. Cheers.
     
    Last edited: Dec 14, 2017
  18. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    Change log for version 1.07 that is now up on the asset store!
    • Many performance improvements to increase fps.
    A longer explanation is, I stopped using intensive math if you set any of the Thresholds to 0. For SendThresholds, this means it'll send out anytime the value is changed at all. For ReceivedThresholds, this means it'll update to the latest received values if the value has changed at all.
    I also no longer set transform if it hasn't changed.

    As always, hit me up with any suggestions or questions.
     
    Last edited: Dec 15, 2017
  19. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    436
    Hey, just tested the new version, it works great!
    Do you know a way for testing the actual bandwidth used ? the unity profiler only gives ticks but not the weight.
     
  20. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @Stabbarey
    I think I'm still not understanding. Why don't you just pass the damage over an RPC?
     
  21. LostPanda

    LostPanda

    Joined:
    Apr 5, 2013
    Posts:
    173
    Hello @Fuestrine how to sync Network Time ? i want use your plugin do network video sync .Thanks
     
  22. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    Last edited: Dec 16, 2017
  23. LostPanda

    LostPanda

    Joined:
    Apr 5, 2013
    Posts:
    173
    @Fuestrine thanks. i am using built in unet solved .I have one other question. I have an old project that is based on tnet and I want to know if it is available using the NAT Traversal plugin?TNet dont support NAT punch-through.
     
  24. jessejarvis

    jessejarvis

    Joined:
    Aug 9, 2013
    Posts:
    303
  25. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @LostPanda
    I have no clue how TNet actually works but I would think it would be possible to use NAT Traversal with TNet via the NATHelper component. Punchthrough and port forwarding are totally separate things that happen before a network connection is made so it should work with just about anything but I give no promises. I don't recommend it though unless you have some coding experience if you are using a separate system from UNET.
     
    Last edited: Jan 3, 2018
  26. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @jessejarvis
    I'm not sure how that works but Smooth Sync uses UNET so if it uses UNET, I would say it can use Smooth Sync. I don't think I've dealt with anyone making an MMO type with Smooth Sync yet so if you do buy it and have any feature requests, let me know.
     
  27. jessejarvis

    jessejarvis

    Joined:
    Aug 9, 2013
    Posts:
    303

    None of the "MMO Controllers" actually come with networking movement. They're just standard character controllers but in MMO style. That's why I was hoping this would actually make it work for UNET, thing is it needs to be server authoritative.
     
  28. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @jessejarvis
    Yep, Smooth Sync will work with an authoritative server and syncs any transforms.
     
  29. kiamisu

    kiamisu

    Joined:
    Jan 3, 2018
    Posts:
    1
    I am working on a fast paced 2D game, does smoothsync do any kind of lag compensation or prediction beyond what you would find in the UNET network transform? Is it capable of providing a smooth sync without destroying the simulation due to over-interpolation?
    For example, if you have a ball bounce back and forth in a small 2d room at a high velocity, will it be possible to accurately hit it with a player, and will it actually bounce off the walls properly rather than leaving big gaps along the edges?
     
  30. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @kiamisu
    Smooth Sync has a back time so you're always some time in the past so that the position is more accurate which compensates well for lag because with some lag, the object will always be where it once was. Network Transform doesn't have this.

    I'm not sure what you mean about providing a smooth sync without destroying the simulation due to over-interpolation. It's smoother than Network Transform but I never specifically tested resource intensity wise but I do a hundred on the screen no problem.

    I hesitate to say anything definitive about the accuracy because it's not going to be as accurate as you want. It's networking and it's never going to be great but it should be more accurate than Network Transform.

    Generically, it only sends an update at your desired time lapse. If you hit an edge in between this time and bounce off, it'll think it never traveled to the edge. I'm working on something now (will probably be live within the week) where you can update the state at any time if you want to update the position at a collision or when you turn fast or whatever you want but there's no real generic way to do it that I can think of so you'll have to tell it when to update for specific things like that.
     
    Last edited: Jan 7, 2018
  31. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    Version number 1.08 is now on the Asset Store!
    • Added ability to update Transform in Update() or FixedUpdate().
    This will make your objects buttery smooth but it's not really recommended for physics since it won't be using things like Rigidbody.MovePosition();​
    • State buffer size increased based on interpolation back time.
    Can now have very large interpolation back times.​
    • Added ability to send out state at any time.
    Useful for fast direction changes.​
    • Added example scene information for those wishing to change object authority during runtime.
     
  32. Sunny2017

    Sunny2017

    Joined:
    Jul 6, 2017
    Posts:
    1
    Is it only used for LAN?
     
  33. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
  34. Lazdena

    Lazdena

    Joined:
    Aug 23, 2013
    Posts:
    5
    I just bought the plugin and it's working great, but I need some extra functionality and wanted to ask before tearing it apart.

    I have a 2D sprite based game and I use the localScale to flip the sprites left and right. Is there an easy way to make it snap to the most recent localScale sent from the authority? Specifically snapping and not interpolating, as that would look weird.

    Right now I'm trying to just retrofit it into the plugin, but I could probably just tack on a simple script alongside it to sync just the scale.
     
  35. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @Lazdena
    I've been waiting for someone to ask for scale syncing! I'll add it in the next update. I'll have time at some point in the next few days. I'll let you know when I'm finished.

    If you are looking to do it yourself before I get the time, send it over like I send over the position and instead of interpolating, set it instantly. There's probably some side issues that I'm forgetting though.

    My guess is the flip is based on movement direction though? You might be able to base it on local direction changes and save the bandwidth.
     
    Last edited: Jan 30, 2018
  36. Lazdena

    Lazdena

    Joined:
    Aug 23, 2013
    Posts:
    5
    Awesome!

    I would make it based locally, but I do flip them without movement for things like attacking and such.

    The code was simple and clean enough that I was able to add in the scale syncing with a few quirks. I'll just wait for your update. Thanks so much for the quick reply.
     
  37. ivaylopg

    ivaylopg

    Joined:
    Dec 17, 2015
    Posts:
    2
    Ooh..definitely would love to see ability to sync scale! Thank you!
     
  38. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @Lazdena @ivaylopg
    I've just submitted the new version to the Asset Store with scale syncing! It usually takes about a week to get approved.

    Email me at the support email with your invoice number and the version of Unity you use if any of you want it sooner.
     
  39. chipity

    chipity

    Joined:
    Dec 21, 2016
    Posts:
    7
    Hey man interested in porting your asset to photon am i able to get a copy for free to see if its possible. No worries if not.
     
  40. Pusuke

    Pusuke

    Joined:
    Oct 13, 2014
    Posts:
    1
    Hi! I've bought this Asset today.
    This is very Good Asset.

    But I have been facing problem that Rigidbody over network.
    When AddForce to Rigidbody, there were different move distance.
    Client was less move than Server.

    How can I resolve this problem?
     
    Last edited: Feb 4, 2018
  41. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @Pusuke
    The example scene uses AddForce to Rigidbodies but nothing like this is happening in the example scene for me. Maybe take a look at it and see if you are doing anything differently.

    Try re-adding the SmoothSync script to return to the default variable settings to make sure you don't have too wonky of settings.

    Let me know if you still have problems.
     
  42. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @cryptexslayer
    I show how to port to Photon here. I've not heard back from the people who requested the help so it seems to work fine with Photon but I make no guarantees if you purchase it and it doesn't work with non-advertised systems.
     
  43. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    Version 2.0 is now on the Asset Store!

    Version 2.0 means updating to this will cause some variables to revert to default. Make note of your current variables and note that some behaviors have changed.
    • Added ability to sync scale.
    • Added separate LERP speeds for position, rotation, and scale.
    • Renamed variables to be better described. Keep in mind your variables may be changed.
    • Clearer comments everywhere.
    • Allow 0 use of receivedThresholds and snapThresholds to save performance. Most people will want the received variables at 0.
    • Cached some other variables to save performance, average user will use 6 less distance checks a frame.
    • Changed default SmoothSync variables to be more useful for the average user.
    • In general moved a lot of code around and consolidated.
    As always, before it shows up on the Asset store, hit me up at the support email if you just can't wait to get your hands on this juicy piece of code. Put your invoice number in the email if you haven't provided it to me before.
     
    Last edited: Feb 8, 2018
  44. Lazdena

    Lazdena

    Joined:
    Aug 23, 2013
    Posts:
    5
    Ah, was tracking down a bug in the plugin for the last two days, wasn't sure if it was my implementation. It looks like it syncs from Server > Client and Client > Server just fine, but I noticed it did not sync Client > Client at all.

    Finally managed to track it down though. The cause came from the state Serialization of clients rerouting from the server. The clients only turn their "should send" flags on when they have authority. So Client A would send their position to Server, Server would grab it and forward it to Client B, when serializing the state Server would check the "sendPosition" flag on Client A, find it to be false, and not forward the position.

    I fixed this by moving the "Checks the core variables to see if we should be sending them out" block to be above the "We only want to send from owners who are ready" block. So now when Client A's position changes on the server it is forwarded to Client B properly.

    I still don't think this is an optimal fix, because I think the two Updates before the Serialization could cause it to skip a state. I don't know enough about the inner workings on the networking API to know whether or not that could happen though.

    Oh well, seems to be working for now.
     
  45. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @Lazdena
    Thanks for the find! I can't believe that slipped through on my last performance increases. Sorry about that.

    That fix you said works fine from a quick test I just did. I think it loses some performance increases I was trying to do though so I'll have to take a closer look tomorrow and wrap it all up nicely.

    I'll PM you the new build tomorrow and submit it to the asset store. Anyone else PM me here or email me with your invoice number and I'll get you the new build if you want it before it gets accepted to the store.
     
  46. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    Version 2.01 is now on the Asset Store!

    Change log:
    • Use one less distance check when extrapolating.
    • Fixed a client to client syncing issue that started in the previous update.
    I'm always up for listening to ideas if anyone wants some extra functionality. Let me know!
     
  47. MicahDuck

    MicahDuck

    Joined:
    Nov 25, 2016
    Posts:
    8
    @Fuestrine Is it possible to change what is syncd while running? I tried

    GetComponent<Smooth.SmoothSync>().syncRotation = Smooth.SyncMode.XYZ;

    from just the Y. No dice tho, any help would be great
     
  48. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @Micahdog
    I'm away from my computer for a few days, but I think you'll just have to send an RPC out to change the SyncMode on the object on each computer.

    I'll look deeper into it this weekend if you want to wait for me to check it out. It at least sounds like something I should show how to accomplish in the example scene. Thanks for the tip.
     
  49. farshmak

    farshmak

    Joined:
    Jun 17, 2014
    Posts:
    3
    @Fuestrine any ideas on how to make it smoother for the jumps in my 2D platformer? Playing with using / not using velocity, lerp speed, and send rate didn't work.
     
  50. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @farshmak
    Try looking at the variable whereToUpdate and changing that. Let me know how it goes.