Search Unity

  1. 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:
    586
    @JunJie93
    Call Awake() on both the Smooth Sync syncing the parent and the Smooth Sync syncing the child.
    Call ClearBuffer() after Awake(). (May not be needed but easy to try if the above doesn't work)

    The child can have SmoothSync only in certain networking systems. Take a look at the example scene provided by Smooth Sync for your networking system to see how a parent/child Smooth Sync should be setup in the scene.
     
  2. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    586
    @rtking1993
    Thanks for the kind words!

    In order to make SmoothSync have a more reactive feel, try the following:
    Try lowering InterpolationBackTime. (but keep above 1/sendRate or it may appear jittery due to consistent extrapolation). Mouse over the SmoothSync variables for more information/limitations.
    Try raising the Easing Speeds.
    Try raising Time Correction Speed. (do this last and slow probably as it will get very jittery very quickly)
     
  3. Yi-GPS

    Yi-GPS

    Joined:
    Jan 21, 2020
    Posts:
    5
    Hi. We have been using SmoothSync with a previous version of Netcode for Gameobjects with no issue. However when we update the Netcode package to [1.0.0-pre7] we get a compiler error. Is there any plan to fix that? Thanks.
     
  4. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    586
    @Yi-GPS
    Thank you for letting us know. If that is an official fully released version of Netcode, then we do plan to support it (or will when it becomes an official release if it currently is not). I have no current timeline but I am a bit swamped right now so it may be around a few weeks or a month. If you have a specific compiler error that you can't figure out, put it here though and I can see if I can think of anything. Cheers.
     
  5. edinho09

    edinho09

    Joined:
    Nov 19, 2019
    Posts:
    17
    i have a button soccer game that each player controls 5 buttons when the buttons collide with each other the buttons don't move what can i do to make them move and how if they become kinematic? each player owns their buttons when I transfer ownership of all buttons to one player the synchronization is not correct
    VIDEO PROBLEM
     
    Last edited: Jun 14, 2022
  6. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    586
    @edinho09
    In order to have perfect physics interaction you will need to have each object owned by the same system, typically this is the server.
     
    Meltdown and edinho09 like this.
  7. edinho09

    edinho09

    Joined:
    Nov 19, 2019
    Posts:
    17
    and how do i do it? my game is with Pun 2
    my server is free for 20 users the problem is not synchronization, but when it collides with the object it doesn't move unless I transfer full ownership of all buttons
     
  8. edinho09

    edinho09

    Joined:
    Nov 19, 2019
    Posts:
    17
    my game connects directly, one is the master and the other is not master, I think it's via udp I don't have a server

    code conection
    Code (CSharp):
    1. private void Start()
    2.     {
    3.  
    4.         //PhotonNetwork.AutomaticallySyncScene = true;
    5.         if (!PhotonNetwork.IsMasterClient && PhotonNetwork.CurrentRoom.PlayerCount == 2)
    6.         {
    7.             foreach (KeyValuePair<int, Player> player in PhotonNetwork.CurrentRoom.Players)
    8.             {
    9.                 if (player.Value.IsMasterClient)
    10.                 {
    11.                     int formation = (int)player.Value.CustomProperties["Formation"];
    12.                     int flag = (int)player.Value.CustomProperties["Flag"];
    13.                     updateRoomProp(is_server: true, flag, formation);
    14.                     StartCoroutine(loadGame(player.Value, flag, formation));
    15.                 }
    16.             }
    17.         }
    18.         if (PhotonNetwork.IsMasterClient)
    19.         {
    20.             player_1_Name.GetComponent<TextMesh>().text = PhotonNetwork.NickName;
    21.         }
    22.     }
    23.  
    24.  
    25.     public override void OnPlayerEnteredRoom(Player newPlayer)
    26.     {
    27.         int formation = (int)newPlayer.CustomProperties["Formation"];
    28.         int flag = (int)newPlayer.CustomProperties["Flag"];
    29.         updateRoomProp(is_server: false, flag, formation);
    30.         StartCoroutine(loadGame(newPlayer, flag, formation));
    31.     }
    32.  
    33.     private void updateRoomProp(bool is_server, int flag, int formation)
    34.     {
    35.         ExitGames.Client.Photon.Hashtable hashtable = new ExitGames.Client.Photon.Hashtable();
    36.         if (is_server)
    37.         {
    38.             hashtable.Add("serverFlag", flag);
    39.             hashtable.Add("serverFormation", formation);
    40.         }
    41.         else
    42.         {
    43.             hashtable.Add("clientFlag", flag);
    44.             hashtable.Add("clientFormation", formation);
    45.         }
    46.         PhotonNetwork.CurrentRoom.SetCustomProperties(hashtable);
    47.     }
    48.  
    49.     private IEnumerator loadGame(Player player, int flag, int formation)
    50.     {
    51.         opponentName.GetComponent<TextMesh>().text = player.NickName;
    52.         opponentName.SetActive(value: true);
    53.         progress.SetActive(value: false);
    54.         PlayerPrefs.SetInt("Player2Flag", flag);
    55.         PlayerPrefs.SetInt("Player2Formation", formation);
    56.         title.GetComponent<TextMesh>().text = "Carregando Jogo...";
    57.         AvatarRandomizer30.matchIsFound = true;
    58.         yield return new WaitForSeconds(3f);
    59.         if (PhotonNetwork.IsMasterClient)
    60.         {
    61.             PhotonNetwork.LoadLevel("Game30-c#");
    62.         }
    63.  
    64.     }
     
  9. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    586
    @edinho09
    Ownership (sometimes called Authority) depends on your networking system.
    Try to look up in the PUN2 docs on how to spawn game objects with Server Authority.
    Then spawn all of your objects in this manner and all of the physics collisions will be great. There's probably a bunch of other ways too, but that's one way to get the desired result of each object owned by the same system.
     
  10. edinho09

    edinho09

    Joined:
    Nov 19, 2019
    Posts:
    17
    when I use this code, the collision works but the object is hit not always in the same position when I hit the ball sometimes the object doesn't even touch the ball in the non master and it is already hit

    Code (CSharp):
    1. if (gameController.GetComponent<GlobalGameManager30>().myShootTurn)
    2.         {
    3.            
    4.             if (!PV.IsMine)
    5.             {
    6.                 PV.RequestOwnership();
    7.             }
    8.         }
     
  11. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,814
    As @Fuestrine says, in order to reliably run a physics simulation, you will need one authority, in most cases a server running the simulation.

    You cannot run the physics on one client, and the physics on another and expect to have a reliable simulation.
    PUN2 is a peer to peer solution and is not built for this.

    I would suggest looking at Photon's Fusion which has built-in support for physics simulation and is much newer tech than PUN2.
     
  12. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    Alternatively you could check out Fish-Networking it has the same features but is free
     
    Last edited: Jun 17, 2022
  13. edinho09

    edinho09

    Joined:
    Nov 19, 2019
    Posts:
    17
    and how do i switch from pun 2 to fish network i will have to recreate everything from new lobby raise event or i can use pun2+fish network
     
  14. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    You can join their discord and ask questions there, its a great community. Alternatively, you can check out their docu's, fairly straight forward.
    It already has a Lobby Worlds (for paid patreon members, which is very cheap btw)
    and no you cannot use pun + fn, should probably chose one or the other.
     
  15. edinho09

    edinho09

    Joined:
    Nov 19, 2019
    Posts:
    17
    so is it correct to change the property in photon pun2? or recommend a better way because it has a small delay when changing the property and hitting another object
    Code (CSharp):
    1. if (!PV.IsMine)
    2.             {
    3.                 smoothSync.clearBuffer();
    4.                 PV.RequestOwnership();
    5.                 smoothSync.forceStateSendNextOnPhotonSerializeView();
    6.             }
     
    Last edited: Jun 23, 2022
  16. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    586
    @edinho09
    Delay between what happening?

    If it's for your network change, I'd probably just change the network for each turn as yours looks maybe turn based.
    If it's on the physics collision, maybe check that all objects are owned by the same system. They should be if you want great perfect hands-off physics.
     
  17. edinho09

    edinho09

    Joined:
    Nov 19, 2019
    Posts:
    17
    when I hit a ball on the master screen on the client screen it shows that it was hit even before the object touches the ball how should I proceed should I leave a longer delay on the ball than on the player? everyone is like this photo, both the ball and the players?
     

    Attached Files:

  18. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    586
    @edinho09
    Are all of your objects owned by the same system? This is the only real way to get physics to line up well.
     
  19. edinho09

    edinho09

    Joined:
    Nov 19, 2019
    Posts:
    17
    my game is in shift like soccer stars when the shift ends everything is transferred to the other player. when player A hits the ball player B on the other screen sees the ball being hit before it is actually hit, understand?
     
  20. mopl_unity05

    mopl_unity05

    Joined:
    May 2, 2019
    Posts:
    1
    Hi guys am using you smoothSyncPUN2 plugin i am using it to make an AirHockey multiplayer game. I recently came across a bug where my puck(coin) reset to a position near me after the it hits the player handle, there is a owner change whenever the puck(coin) hits the players.The gameobject has rigidbody, colliders and have attached the smoothSyncPun2 script to the puck and photon view observes it. Can You guys suggest me a solution.
     
  21. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    586
    @mopl_unity05
    Do you have "Smooth Authority Changes" checked on the SmoothSyncPUN2 component?
    If not, please turn this option on and try again and let me know if the issue persists.
     
  22. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    586
    @edinho09
    It sounds like not all objects are owned by the same system.
    I would double confirm that all objects are owned by the same system. The ball and the pucks at least. This is required in order to have collision physics work well.

    Do you have a time in your video above where this issue occurs?
     
  23. F22arecool

    F22arecool

    Joined:
    Mar 6, 2022
    Posts:
    3
    Hello I am making a VR game. I need the players to grab a bow and arrows. What settings are the best to have enabled for this? I have smooth authority changes enabled but the players that are not the host cannot move the bow. Also what does the use local transform only option do?
     
  24. F22arecool

    F22arecool

    Joined:
    Mar 6, 2022
    Posts:
    3
    I'm using pun 2
     
  25. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    586
    @F22arecool
    I would start with default settings and then work your way through the mouseovers on the settings starting from the top with some of the most "effective" variables.
    Smooth Authority Changes is good if you are changing authority.

    It sounds like your host owns the bow if your other players can't move it. You'll have to change ownership via how the PUN2 docs say to do it, or send over some RPC to tell the host to move it.

    Using local transform uses things like local position: https://docs.unity3d.com/ScriptReference/Transform-localPosition.html
     
  26. edinho09

    edinho09

    Joined:
    Nov 19, 2019
    Posts:
    17
    how much would you charge to connect via remote assistance and help me set up my game? It needs little adjustments, it's already ready, even published on google play and something aesthetic I think in 10 minutes you would solve this?
    my game: https://play.google.com/store/apps/details?id=com.ccs.futeboldebotoes
     
  27. F22arecool

    F22arecool

    Joined:
    Mar 6, 2022
    Posts:
    3
    Hello again, so for VR multiplayer, what benefits does enabling local transforms actually have? Does it make the game more reactive somehow? And if I can transfer ownership using a separate script, what will the enable smooth transfer actually do to improve this process?
     
  28. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    586
    @edinho09
    Sorry but my day job and regular support keeps me very occupied. I am not taking any other paying gigs at the moment.
    I'm always happy to answer specific questions though if you have them.
     
  29. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    586
    @F22arecool
    Certain VR systems use only local transforms. This option is for those systems. If yours works fine with it unchecked, then it's probably fine to leave it unchecked.

    If you are talking about the Smooth Sync option of "Smooth Authority Changes", then it will just make Smooth Sync be able to automatically handle your ownership changes instead of you having to call a method. It'll also be able to automatically Smooth it out a bit. You'll notice a jump if you just call the method we suggest on our docs page instead of using this option.
     
  30. Stanley_DBI

    Stanley_DBI

    Joined:
    Feb 18, 2022
    Posts:
    17
    Hello, I'm using Smooth Sync for Mirror and also use Distance Interest Management from Mirror. It syncs position & rotation just fine, but I'm having trouble syncing the scale. I use it to sync health bar scale from values in the server. It works when I'm not using interest management, but since I'm developing some sort of auto battler game, the bandwidth gets higher the more the player buys heroes. Interest management ensures that player only syncs position, rotation of heroes they're looking at (near the player), but for some reason the health bar scale just won't sync. Any ideas why?
     
  31. chithanhlnbp2016

    chithanhlnbp2016

    Joined:
    Oct 22, 2020
    Posts:
    2
    I just purchased your property with invoice number 18967385400328.
    I'm currently looking to embed it in a dedicated server with DarkRift Networking 2. I can't find any examples for this, can you spare some help?
    I just need to sync position and rotation.
     
  32. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    586
    @chithanhlnbp2016
    Smooth Sync does not have drop-in support for DarkRift Networking 2. If you believe you bought Smooth Sync in error, I am always happy to offer a refund. PM me your invoice number. Invoice numbers start with IN typically so you may have previously given me a different number.

    If you wanted to get DarkRift Networking 2 working with Smooth Sync, you would have to do the work yourself. I'd probably start off with a system like PUN or PUN2 as that version explicitly makes and sends byte arrays across the network and most networking systems can do something similar.
     
  33. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    586
    @Stanley_DBI
    Nothing really comes to mind unfortunately. I don't see much difference between how we handle scale and how we handle position/rotation so just scale not working is definitely stumping me.
    Unfortunately I'm a bit swamped with my day job right now so I won't be able to dig into the issue myself. Always happy to offer a refund though if Smooth Sync is not living up to your expectations.

    If you want to look into it yourself though, take a look around the setScale() and shouldSendScale() methods (maybe getScale() too) in SmoothSyncMirror.cs. I would think It's either not sending it, or not setting it upon receive. Working from there should let you know which one it is. Please don't hesitate to reach out with any questions. Cheers.

    EDIT: Just thought of something, are you ONLY changing scale when scale refuses to sync? Or is position and rotation also changing at this same time?
     
  34. chithanhlnbp2016

    chithanhlnbp2016

    Joined:
    Oct 22, 2020
    Posts:
    2
    Here is my invoice number:
    IN010201725809
    Actually for the past 2 days I have been trying to code but can't use this code for my project. I've been using banana's AnySync for now and it's been pretty effective.
    I'm not greedy for $15 but I really can't use it.
     
  35. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    586
    @chithanhlnbp2016
    With Smooth Sync not supporting your networking system, I think that is wise.
    I have put in your refund request. It's usually fairly quick but they say to give it up to two weeks to go through. If you don't see it within two weeks, reach out and I will request it again through Unity. Thank you.
     
  36. Stanley_DBI

    Stanley_DBI

    Joined:
    Feb 18, 2022
    Posts:
    17
    I'm only changing the scale. For now I use Mirror's network transform to sync the scale and Smooth Sync for position and rotation. Works fine at the moment.
     
  37. EnvisionGames

    EnvisionGames

    Joined:
    Sep 24, 2019
    Posts:
    12
    Hello, are you going to support Photon Fusion with Smooth Sync? I love Smooth Sync for Pun2 and Fusion needs it too!
     
  38. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,814
    I thought all that stuff was built into Fusion?
     
  39. EnvisionGames

    EnvisionGames

    Joined:
    Sep 24, 2019
    Posts:
    12
    They have Lag Compensation and Tick Based Rollback if you use Fusion in Server Mode and some other features. They Lack Smooth Rigidbody Syncing when using multiple Rigidbodies on one Gameobject. With Smooth Sync Asset for Pun2 it is super smooth.
     
    Meltdown likes this.
  40. handisantoso45

    handisantoso45

    Joined:
    Jun 30, 2021
    Posts:
    1
    Hos fix this
    Assets\Smooth Sync\PUN2\Smooth Sync Asset\SmoothSyncPUN2.cs(30,78): error CS0535: 'SmoothSyncPUN2' does not implement interface member 'IOnPhotonViewOwnerChange.OnOwnerChange(Player, Player)'
     
  41. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    586
    @MagicUnit
    Unfortunately my day job is keeping me too busy to make a Photon Fusion version. I have no current plans to implement that compatibility at this time.
     
  42. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    586
    @handisantoso45
    My initial guess is you will want to confirm you are using the latest version of Smooth Sync and the latest version of PUN2 that are available on the Asset Store.
    If you confirm this, does this happen in the example scene provided by Smooth Sync for PUN2?
     
  43. wechat_os_Qy00ad1jKn5TY6BLX1cvokD9g

    wechat_os_Qy00ad1jKn5TY6BLX1cvokD9g

    Joined:
    Apr 28, 2022
    Posts:
    1
    The camera will shake when it follows the physical objects. I guess it is the position update problem. Is there any solution
     
  44. blabz2007

    blabz2007

    Joined:
    Nov 19, 2013
    Posts:
    8
    Getting this error in SmoothSyncNetcode.cs with latest Netcode for GameObjects
    Line 1077:
    Cannot access static constant 'ServerClientId' in non-static context
     
  45. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    586
    Try to change the WhenToUpdate variable on Smooth Sync to be the same as when your camera updates. Or change your camera update time to be the same as Smooth Sync.

    Let me know how it goes.
     
  46. Max_power1965

    Max_power1965

    Joined:
    Oct 31, 2013
    Posts:
    127
    Hello
    I have the following code used to spawn on object on the server:
    Code (CSharp):
    1. [ServerRpc(RequireOwnership = false)]
    2.     private void TransmitBubbleCloneStateToServerRpc()
    3.     {
    4.         GameObject goInstance = CloneBubbleLocal();
    5.         goInstance.GetComponent<NetworkObject>().Spawn();
    6.     }
    7.  
    8.     private GameObject CloneBubbleLocal()
    9.     {
    10.         GameObject goInstance = Instantiate(this.gameObject);
    11.         goInstance.transform.localScale = gameObject.transform.localScale / 2;
    12.         goInstance.GetComponent<BallColorNetworkManager>().UpdateBallColor(GetComponent<SpriteRenderer>().color);
    13.         goInstance.GetComponent<StandardBubbleManager>()
    14.             .InitBubble(this.GetComponent<StandardBubbleManager>().NumberOfTapBeforeDestroy.Value - 1);
    15.         return goInstance;
    16.     }
    What this code does is simply take the actual game object, and create a clone which is half of the scale of the actual one. The problem is that when the object get spawned on the client, for few istantans I can see the original size of the gameObject and then It'll will snap to the new value. What I would like to have is that when the object get spawned on the server, It should be half of the size of the previous one instantly. This does not happen if I use the standard Unity Network Transfer Component.
    Also, attached the configuration of my Smooth Sync component.
     

    Attached Files:

  47. Max_power1965

    Max_power1965

    Joined:
    Oct 31, 2013
    Posts:
    127
    In addition to the latest post: I also have another problem,
    Sometimes, when an object gets de-spawned on the server, on the client I have the following error:
    Code (CSharp):
    1. KeyNotFoundException: The given key '9' was not present in the dictionary.
    2. System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at <612a2c65aaf843d698f8d38b2ad7654a>:0)
    3. Smooth.StateNetcode.Deserialize (Unity.Netcode.FastBufferReader reader) (at Assets/Smooth Sync/Netcode for GameObjects/Smooth Sync Assets/StateNetCode.cs:391)
    What is wrong here?
    I must say that if I use the standard Unity Transform I don't have any problem
    to add more context. its seams that inside the method: "public static StateNetcode Deserialize" in the StateNetcode class, the object is trying to access a non exsisting object: NetworkManager.Singleton.SpawnManager.SpawnedObjects[netID], the problem is that this method should no be called at all because the object has been destroyed
     
    Last edited: Sep 19, 2022
  48. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    586
    @Max_power1965
    It looks like you're being helped on our Discord channel but let me know if not.
     
  49. Zebadiah

    Zebadiah

    Joined:
    Apr 6, 2014
    Posts:
    67
    You just need to reference the ServerClientId statically like NetworkManager.ServerClientId

    Sorry for the issue. It will be fixed in the next release.
     
  50. chdera

    chdera

    Joined:
    Sep 22, 2017
    Posts:
    1
    @Fuestrine

    I had the same problem, the reason was that I didn't have the last version of Photon Pun2, then I updated and imported the last version but the problem persisted. I realized that some scripts couldn't be checked during the re-import (the ones from the interface folder are the ones giving the errors), it's necessary to remove completely Photon from the project and then import the new version. Now I don't have errors on the console and everything is working!
    Hope it helps somebody (I lost 2 hours debugging) :D