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

AnySync - Transform sync for any networking.

Discussion in 'Assets and Asset Store' started by forcepusher, Mar 28, 2018.

  1. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    SmallImage15.jpg
    Asset Store Link
    Documentation Link

    AnySync is an interpolation library designed to help with synchronizing motion over the network. Developers need to use their own network code to utilize it. Netcode could be built using UNet, Photon or any other networking library, including custom ones built from scratch.
    See documentation and asset store links for more info.

     
    Last edited: May 26, 2019
  2. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    Now it's approved and up in the store.

    Reminder - keep all SyncBuffer settings default while testing or integrating this asset for the first time! Custom settings might introduce issues if not used carefully.
    To reset SyncBuffer settings, click on the "Gears" icon on top right of the component and hit "Reset".
    Untitled-122.png
     
    Last edited: May 2, 2018
    yasirkula likes this.
  3. Farwall

    Farwall

    Joined:
    Sep 19, 2014
    Posts:
    18
    I am working on a multiplayer game and its a racing game like Subway Surfer. My problem is when remote player is crossing the local player. there is a jitter on remote player. like player is shaking. but its happening only on remote player. i think its NetworkTransform issue. if i use this "AnySync" to my player perfab will it fix my problem like shake or jitter?
     
  4. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    In a nutshell, AnySync only helps you to interpolate between positions. It has nothing to do with issues like the one you described, because you have to manually apply positions provided by SyncBuffer component via code.

    Final result will only depend on how you set up your character controller and his physics. AnySync is very flexible, but it's not a simple drag-and-drop solution. I'm not sure if you actually need this asset.
    I suggest to try disabling collisions between characters and see if it helps https://docs.unity3d.com/Manual/LayerBasedCollision.html

    If that didn't help, then I might try to figure something out for you and put a solution inside this asset, just like I did with the Photon example.
     
    Last edited: May 3, 2018
  5. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    Last edited: Apr 27, 2018
  6. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    Someone asked for a WebSocket example, so I've made one as well.
    It was quite an effort to create a sample networking using bare websocket-sharp just to apply AnySync on top of it. I really hope that this will be useful some time in the future.
    I also fixed multiple issues with SyncBuffer while I was there, please update to v1.03 when it's up in the store.

    Attaching example package to this post. Read manual section for it here.
     

    Attached Files:

    Last edited: May 3, 2018
  7. Alkanov

    Alkanov

    Joined:
    May 15, 2017
    Posts:
    54
    Hi, does the client sends its positioning to the server? Is there anything I could use to detect speed-hacks or wall-hacks?

    Thanks
     
  8. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    AnySync is just an interpolation library and you can code whatever you like. Example packages of this asset give authority over player position to client, so client is responsible for sending position updates to server - just like in every game using Photon or UNet HLAPI.

    It should be pretty straight forward to catch a speedhacker, because client always sends time between updates (interpolation time) together with positions. Simple calculation like this should be enough.
    Code (csharp):
    1. var movementSpeed = (newPosition - oldPosition).magnitude / interpolationTime;
    To detect someone walking through walls, your server has to use a physics engine (easiest way is to run the server on a Unity instance). Simple raycast check from old position to new position is one of the ways to do it.

    Those are just suggestions. There are hundreds of ways to code your game.
    But remember - unless you're writing an MMO, you should focus on user experience instead of anti-cheating. Any game can be hacked, so it will get bloated with hackers or farming bots if you think you're safe from that issue.
     
    Last edited: May 17, 2018
  9. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    Pretty big update 1.05 was released.
    I've been supporting quite a lot of people over the e-mail and learned a couple of things that need to be improved in the example packages. Here's the list of new things:
    • Added a minimal 2D example that would help with the learning curve. It uses the easiest possible techniques to understand and does not sync anything except position (so it'll work flawlessly with any character controller).
    • Ability to inherit from SyncBuffer and extend it with your custom code. All fields are now protected instead of being private. All important methods are now virtual as well.
    • Removed all settings from Inspector except TargetLatency. This is the only setting that might need to be adjusted for your game. All other settings are still accessible from code in case someone really needs them.
    • Bug fixes in Photon example. Now it works properly if you use multiple observed components in PhotonView.
    This update is up in the store.
     
  10. Zenithin

    Zenithin

    Joined:
    Jun 7, 2016
    Posts:
    35
    Hello! I am trying to use this. My problem is in the case when the lag/ ping is less. It is showing too much rubber band type movement.
    When I disabled the extrapolation it started looking fine.
    Can I somehow link it so that the extrapolation is auto adjusted according to lag/Ping time of the client?
    I do have regular values of client server lag to be fed to anysync if required.

    Regards.
     
  11. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    You can adjust TargetLatency in real time, but I'm not sure if it's the right call.
    I suggest increasing TargetLatency to 0.1 and see if you still have the issue. You have to find the balance between accuracy and latency to decrease rubber-banding (higher TargetLatency increases accuracy).
    I can configure things for you, if you send me a reproduction project with the issue you have.
     
  12. Velcer

    Velcer

    Joined:
    Mar 16, 2017
    Posts:
    21
  13. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    Hello. Thanks for your request, I will let you know when I'll get it done.
    DarkRift2 example package is also on my list. I will try to release them both at the same time.
     
  14. Velcer

    Velcer

    Joined:
    Mar 16, 2017
    Posts:
    21
    Very appreciated !
     
  15. Velcer

    Velcer

    Joined:
    Mar 16, 2017
    Posts:
    21
    Do you by chance have a time frame for this? If it helps, I can pay more for this product.
     
  16. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    I was unable to create a package that would "just work" when you import it, because normal use of Forge involves generating backing code through Network Contract Wizard.
    But here is what example sync code looks like.
     

    Attached Files:

    Velcer likes this.
  17. Velcer

    Velcer

    Joined:
    Mar 16, 2017
    Posts:
    21
    Thank you!
     
  18. Velcer

    Velcer

    Joined:
    Mar 16, 2017
    Posts:
    21
    Hey, would you consider improving this so that one could sync strings, floats, among other types inside of a buffer?
     
  19. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    I'm not sure why you would need that inside a transform syncing asset, but you can derive a class from SyncBuffer and extend it. All fields, properties and methods are either protected, public or virtual.
    Your derived class be compatible with all future updates.
     
  20. MikhaskoS

    MikhaskoS

    Joined:
    Jun 24, 2018
    Posts:
    52
    Hello. Does this asset work with PUN2 ?
     
  21. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    Hello. It definitely does, but the example for classic PUN version won't work with PUN2.
    PUN2 was released like a week ago, so I'll have to create a new example package.
     
  22. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    So I've finished PUN2 example package, attaching it to this message.
    This took way less time than expected.
     

    Attached Files:

  23. MikhaskoS

    MikhaskoS

    Joined:
    Jun 24, 2018
    Posts:
    52
    Thanks. I will experiment.
     
  24. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    Update v1.06 containing PUN 2 example is up in the store.
    PUN 2 is now fully supported.
     
  25. desukarhu

    desukarhu

    Joined:
    Jun 14, 2017
    Posts:
    27
    I get this following error when trying the PUN 2 example:
    Code (CSharp):
    1. IndexOutOfRangeException: Array index is out of range.
    2. Photon.Pun.PhotonStream.ReceiveNext () (at Assets/Photon/PhotonUnityNetworking/Code/PunClasses.cs:642)
    3. AnySync.Examples.PUN2PlayerSync.OnPhotonSerializeView (Photon.Pun.PhotonStream stream, PhotonMessageInfo info) (at Assets/AnySync/Examples/PUN2/PUN2PlayerSync.cs:75)
     
  26. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    Hello. I just tested it with the last version of PUN 2, but didn't run into any issues.
    Could you send me a copy of your project to reproduce it ?

    BTW your stack trace message doesn't match with the example code in last version of AnySync.
    Line 75 is a closing bracket in the PUN2PlayerSync.cs
     
    Last edited: Sep 23, 2018
  27. desukarhu

    desukarhu

    Joined:
    Jun 14, 2017
    Posts:
    27
    Sorry that was my bad it seems. I tried converting the PUN2PlayerSync to use CharacterController instead of rigidbody and failed and I forgot to undo the changes before trying the demo. The demo works after reimporting the script.

    Could you help me with converting it to using charactercontroller? I tried removing all the velocity mentions and changing rigidbody.position etc. to transform.position but it didn't work like that.
     
  28. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    Yeah, I figured I should provide simple examples instead of stuffing every single AnySync feature inside them.
    Try this one, it should be much easier to follow. It uses CharacterController as well.
     

    Attached Files:

  29. desukarhu

    desukarhu

    Joined:
    Jun 14, 2017
    Posts:
    27
    Thank you, I'll try this when I get home from work later today. Sorry for bothering you on your holiday. :)

    Edit: tested it and it worked well, it was missing rotation syncing but it was easy to add.
     
    Last edited: Sep 26, 2018
  30. sasa42

    sasa42

    Joined:
    Jun 6, 2018
    Posts:
    20
    Problem.JPG

    Hello,

    i have following problem:

    Build.exe is connecting fine

    Second instance (here Unity) is hanging in ConnectedtoMaster state.
    Same when i start Build.exe an second time.

    tested with
    Pun 2.0
    Pun 2.1
    Pun 2.2

    The PUN 2 Examples (Asteroid and SlotRacer) are working fine with these settings.

    Do you have an idea?
    Here is the complete log from the second instance.

    LOG.JPG
     
  31. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    Hello. I've recently tested both old and the new example and couldn't reproduce your issue. I randomly get stuck connections as well on any project using Photon, but they aren't related to the code of this example.
    Connection code can't get any easier.
    Code (CSharp):
    1. using Photon.Pun;
    2. using Photon.Realtime;
    3. using UnityEngine;
    4.  
    5. namespace AnySync.Examples
    6. {
    7.     public class PUN2NetworkManager : MonoBehaviourPunCallbacks
    8.     {
    9.         [SerializeField]
    10.         private GameObject _playerPrefab;
    11.         [SerializeField]
    12.         private Transform _startPosition;
    13.  
    14.         private void Start()
    15.         {
    16.             PhotonNetwork.ConnectUsingSettings();
    17.         }
    18.  
    19.         public override void OnConnectedToMaster()
    20.         {
    21.             PhotonNetwork.JoinOrCreateRoom("TestRoom", new RoomOptions(), TypedLobby.Default);
    22.         }
    23.  
    24.         public override void OnJoinedRoom()
    25.         {
    26.             PhotonNetwork.Instantiate(_playerPrefab.name, _startPosition.position, _startPosition.rotation);
    27.         }
    28.     }
    29. }
    Please contact Photon support to get help.
     
    Last edited: Sep 28, 2018
  32. Zincord

    Zincord

    Joined:
    Dec 21, 2013
    Posts:
    14
    Hi,
    Do you have any examples of authoritarian servers?
    movement and slow bullets?
     
  33. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    Hello. You can use this asset for a fully authoritative server, but it's not a proper way to do it.
    I'd use AnySync as a fallback solution if implementing something like this will be way too difficult.

    Answering your original question:
    No, there are no examples of a fully authoritative server in this asset. Only semi-authoritative.
     
  34. Zincord

    Zincord

    Joined:
    Dec 21, 2013
    Posts:
    14
    I liked this asset, I'll buy xD.
    Do you want to create some authoritative server solution?
    Even if it was another asset I would buy it for sure xD
     
  35. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    Thanks a lot for the purchase. I will consider creating an almost-fully-authoritative example for AnySync in the future.
    (Probably when new Unity networking is out that would replace UNet).

    Currently multiple customers requested me to modify AnySync to sync other variables besides just position and rotation, so this is high priority feature request in my queue. I will implement it via something I call "Delayed Action Execution", where you can specify a method (or a delegate) to execute in sync with the movement.
     
  36. Zincord

    Zincord

    Joined:
    Dec 21, 2013
    Posts:
    14
    Cool xD
    It already has an release date for the "Delayed Action Execution"?
     
  37. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    I got hired to write netcode for a battle royale game, where I integrated AnySync on day one. As soon as I get to the task of implementing this new feature, I will update the asset as well.
    Should be pretty soon, but don't take my word for it yet.
     
  38. Meatloaf4

    Meatloaf4

    Joined:
    Jul 30, 2013
    Posts:
    183
    The asset looks great. A few questions for you.

    Will the asset auto teleport an object if it gets too far out of sync?

    Also how might this work with animations and mecanim. I'm assuming in syncing movement variables (velocity and such) all animations would be done client side around those synced variables. Is this correct?

    Thanks in advance!
     
  39. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    Hello and thank you.

    The logic used behind this asset does not suffer from issues such as "getting too far out of sync", since it uses a keyframe-based motion with flexible time intervals. If a severe extrapolation error occurs during a lag spike, you can set "ExtrapolationPositionDrift" and "ExtrapolationRotationDrift" fields of SyncBuffer to 0, which will instantly correct it and teleport the character instead of trying to keep it smooth.

    When it comes to animations, you're correct - it would do whatever you'll code on the client side. The easiest solution would be using a "Velocity" property of the SyncBuffer. Velocity can get transferred over network and defined explicitly, or calculated from keyframe positions if no velocity was specified.
     
  40. Arsonide

    Arsonide

    Joined:
    Nov 16, 2009
    Posts:
    43
    I'm using this tool, and found it to be quite accurate at low velocities. I use its position to SetPosition on the rigidbody in FixedUpdate, and its velocity to set velocity. This results in very smooth movement, whereas directly setting position and rotation as per the examples gets jittery at even low to medium velocities.

    While the movement is smooth, the higher the velocity, the greater the "positional error" I am noticing between each client. I am using two test machines on my local network and if I accelerate them both at the same time, keeping them together on one machine, they will drift apart on the other.

    Is there anything I can do to combat this, or is this simply the nature of interpolated multiplayer code? Ideally I'd like for two clients to be able to achieve high velocity and chase each other without such great positional offsets. The speeds aren't that great, and it's only two dimensions, so I must be doing something wrong. Is there something I need to adjust as velocity increases? (I am assuming this is the case.)
     
  41. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    Hello. In order to completely compensate the latency, you need to adjust TargetLatency for remote players at run time.

    First, you need to gather the time it takes to deliver the message from remote client to you.
    (It's not "Ping Time", nor the "Latency" or "RTT". You need to find a function that will compare timestamps, like NetworkTransport.GetRemoteDelayTimeMS)
    Then you put the negative of that delay into TargetLatency for the remote player object. This might cause severe extrapolation errors because that player object will attempt to extrapolate way in the future, but it'll do the trick. Make sure to send velocities and maybe accelerations over the network in that case.
     
    Last edited: Oct 22, 2018
  42. MustangLM

    MustangLM

    Joined:
    Feb 6, 2015
    Posts:
    35
    Is it good with high velocity objects ? such as cars ? most interpolation techniques start to jitter very bad at high velocities, so the best option is to use velocity syncing, that has its own problem, which is making sure the position is correct and fixing it if not, how good does this asset handle these problems ?
     
  43. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    It's using extrapolation and smooth extrapolation error correction. AnySync was designed with racing games in mind, but I would still suggest using a deterministic simulation instead if you want the best possible experience.

    The only issue you will run into is that vehicles will clip through walls and floor on high velocity collisions when you set a negative TargetLatency value, so you will have to write custom code that would prevent that.
    Currently I won't have time to write that custom code for you.
     
  44. MustangLM

    MustangLM

    Joined:
    Feb 6, 2015
    Posts:
    35
    @forcepusher Okay, I used unet advanced example on a simple scene with 2 capsule players, the syncing is extremely good ! even on high velocities, but I am having a weird issue, a slow collision between these capsule would send each one to space, I think there is something wrong like, they are fighting for position, what would you suggest to fix this problem ? because collision is important in my project, I don't want it perfect, but at least good collision results over network
     
  45. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    There's quite a few different ways to solve it.
    • First I would suggest trying to use Rigidbody.MovePosition method because it will properly push other physical objects instead of sending them into space by setting transform.position directly.
    • If that doesn't work, try using Rigidbody.SweepTestAll against colliders of other players, and simply constrain the movement to stop where it hits other player.
    • Then you can switch to using built-in CharacterController instead of capsule collider. PUN 2 example uses CharacterController if you need an idea how to use it.
    • If nothing works at all, you can switch off the collisions between player objects and use Triggers to write your own custom collision handling code.
     
  46. MustangLM

    MustangLM

    Joined:
    Feb 6, 2015
    Posts:
    35
    - switching to Rigibody,MovePosition introduced jittery movement since position will get updated in FixedUpdate
    - I haven't looked into the Rigibody.SweepTestAll thing, But I'll look into it
    - I can't change the collider since I'll be using mesh collider, I am testing on capsules before implementing it on my vehicles
    -Custom Collision handling, I have tried writing my own handling script but I ran into a lot of problems, could you provide more information, I used to get all contact points and then add force to these, but I cant get it to work like a normal collision
     
  47. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    You can use MovePosition in the Update loop.
    https://answers.unity.com/questions/291070/moving-rigidbodies-with-movepositionmoverotation-o.html
    Custom collision handling is a last resort and I didn't implement anything like that, nor recommend it.
     
  48. MustangLM

    MustangLM

    Joined:
    Feb 6, 2015
    Posts:
    35
    @forcepusher I tried it in update, the same jitter is still there
     
  49. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    Are you sure you have isKinematic set to true ?
    If that still doesn't work, try enabling rigidbody interpolation.
     
  50. MustangLM

    MustangLM

    Joined:
    Feb 6, 2015
    Posts:
    35
    Yes isKinematic is set to true for non owned obejcts, and I tried all types of interpolation, the collision problem was fixed and is near perfect, but there is jitter at low velocities