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. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @GreenRanchGames You should probably be sending that attachToMe property via RPC so that all clients know which object to attach to. Right now you're setting it for everyone in OnTriggerEnter but a client may receive the RPC saying to attach before they've entered the trigger on their screen, so they wouldn't know what to attach to. I'm not sure if that's really your issue here though.

    You could try calling clearBuffer() after setting useLocalTransformOnly to get the old non-local data out of the buffer.

    Ideally if everything goes right there shouldn't really be any jittering when on the platform when using useLocalTransformOnly as long as the player is actually a child of the platform. Just to make sure you've got things set up right you may want to try setting up a scenario where the player starts already attached to the platform and set to useLocalTransformOnly. If you find that it works in that scenario, but not when attaching at runtime, and clearBuffer() doesn't help, then there may be some issue with Smooth Sync and changing parent/child relationships so let me know.
     
  2. GreenRanchGames

    GreenRanchGames

    Joined:
    Dec 18, 2020
    Posts:
    9
    This was exactly the issue. Including that property in the RPC made the attaching and re-parenting function like intended. No issues with Smooth Sync. Big thanks!!
     
    thegreatzebadiah likes this.
  3. Sholms

    Sholms

    Joined:
    Nov 15, 2014
    Posts:
    85
    Hi I recently by this asset, is there any plan to create a TNet 3 support? I was trying to modify the pun version, but I fail :c
     
  4. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    No plans at the moment but I'll put it on the list and let you know if it happens. You may want to consider starting from the Mirror or UNet versions of the code instead of PUN if you're going to attempt to modify it yourself. I at least find that setup easier to follow, though I guess it really depends on which is closest to TNet and that I do not know. @Sholms
     
    Last edited: Feb 11, 2021
  5. ArcherSS

    ArcherSS

    Joined:
    Apr 7, 2018
    Posts:
    39
    Hi, is this fix available on Asset Store? I just download newest version Mirror and Smooth, but still get this error.

    'MessageBase' is obsolete: 'Implement NetworkMessage instead. Use extension methods instead of Serialize/Deserialize, see https://github.com/vis2k/Mirror/pull/2317'
     
  6. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @ArcherSS The latest version of Smooth Sync should work with the latest version of Mirror. I know Unity has had some issues with updating assets recently though, so make sure you've actually got the latest Smooth Sync. You may want to try completely deleting it and reimporting. Also don't forget you need to re-extract the SmoothSyncMirror.unitypackage after updating or importing.
     
  7. XSquare2

    XSquare2

    Joined:
    May 7, 2018
    Posts:
    8
    Hello, I just bought an asset yesterday and ran into a sync problem. I have a character that is controlled by a rigid body and I send a message to one of them via RPC with float x, and he accepts and commits rb.Addforce (x); At the same time, the character moves sharply, and the local copy has a large delay, with a ping of about 80, the delay is about 0.4s, it annoys me, experimenting with the settings I did not achieve good results, by the way, the same problem is observed with the standard Transform View PUN2. Please tell me what I can do, maybe I'm doing something wrong? I am using the latest version of the asset and the latest version of PUN2. Unity 2019.4.20. And sorry for my english
     
  8. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @XSquare2 I'm not sure I'm following. Who is the owner of the object and who applies the force? If you've got a client owner you shouldn't need an rpc, just apply the force on the owning client and the movement will be synced. If you want the server to be the owner you'll need a separate client owned object that the client can use to send a command to the server to tell it to apply the force to the server owned Smooth Synced object. In that case you should expect pretty significant delay before the owning client sees a reaction to their input. Generally the solution to this is client-side prediction, but unfortunately Smooth Sync doesn't implement anything for that, so you'll have to come up with your own solution.
     
  9. ArcherSS

    ArcherSS

    Joined:
    Apr 7, 2018
    Posts:
    39
    Thanks very much, I have fixed this issue. I install two versions of Unity, and download old version SmoothSync in one of them, then in a new version project, the package manager show newest SmoothSync version, but will always import the old version. Just need to upgrade it on the other version unity project.
     
  10. Wraix

    Wraix

    Joined:
    Oct 2, 2012
    Posts:
    4
    Greetings. I bought Smooth Sync recently and i get an error on the server when a client joins which makes the client disconnect. If the client reconnects it does not happen again, but if a second client join then both clients gets disconnected. Any ideas what might be going on?

    I am using SmoothSyncMirror on my player character with rigidbody and a moving platform with rigidbody. The update is set to FixedUpdate.

    Code (CSharp):
    1. Exception in MessageHandler: NullReferenceException Object reference not set to an instance of an object
    2.   at Smooth.SmoothSyncMirror.addTeleportState (Smooth.StateMirror teleportState) [0x00081] in /Users/mnk/git/cybertron/CoOp/Assets/Smooth Sync/Mirror/Smooth Sync Asset/SmoothSyncMirror.cs:1820
    3.   at Smooth.SmoothSyncMirror.UserCode_CmdTeleport (UnityEngine.Vector3 position, UnityEngine.Vector3 rotation, UnityEngine.Vector3 scale, System.Single tempOwnerTime) [0x00046] in /Users/mnk/git/cybertron/CoOp/Assets/Smooth Sync/Mirror/Smooth Sync Asset/SmoothSyncMirror.cs:1767
    4.   at Smooth.SmoothSyncMirror.InvokeUserCode_CmdTeleport (Mirror.NetworkBehaviour obj, Mirror.NetworkReader reader, Mirror.NetworkConnectionToClient senderConnection) [0x00034] in <f9c1178e5deb41e9ad24a623251e4922>:0
    5.   at Mirror.RemoteCalls.RemoteCallHelper.InvokeHandlerDelegate (System.Int32 cmdHash, Mirror.MirrorInvokeType invokeType, Mirror.NetworkReader reader, Mirror.NetworkBehaviour invokingType, Mirror.NetworkConnectionToClient senderConnection) [0x00019] in /Users/mnk/git/cybertron/CoOp/Assets/Mirror/Runtime/RemoteCallHelper.cs:153
    6.   at Mirror.NetworkIdentity.HandleRemoteCall (System.Int32 componentIndex, System.Int32 functionHash, Mirror.MirrorInvokeType invokeType, Mirror.NetworkReader reader, Mirror.NetworkConnectionToClient senderConnection) [0x00073] in /Users/mnk/git/cybertron/CoOp/Assets/Mirror/Runtime/NetworkIdentity.cs:1105
    7.   at Mirror.NetworkServer.OnCommandMessage (Mirror.NetworkConnection conn, Mirror.CommandMessage msg) [0x000cf] in /Users/mnk/git/cybertron/CoOp/Assets/Mirror/Runtime/NetworkServer.cs:1041
    8.   at (wrapper delegate-invoke) System.Action`2[Mirror.NetworkConnection,Mirror.CommandMessage].invoke_void_T1_T2(Mirror.NetworkConnection,Mirror.CommandMessage)
    9.   at Mirror.MessagePacker+<>c__DisplayClass6_0`2[T,C].<WrapHandler>b__0 (Mirror.NetworkConnection conn, Mirror.NetworkReader reader, System.Int32 channelId) [0x000ca] in /Users/mnk/git/cybertron/CoOp/Assets/Mirror/Runtime/MessagePacker.cs:120
    10. UnityEngine.Logger:Log (UnityEngine.LogType,object)
    11. Mirror.ILoggerExtensions:LogError (UnityEngine.ILogger,object) (at Assets/Mirror/Runtime/Logging/LogFactory.cs:82)
    12. Mirror.MessagePacker/<>c__DisplayClass6_0`2<Mirror.CommandMessage, Mirror.NetworkConnection>:<WrapHandler>b__0 (Mirror.NetworkConnection,Mirror.NetworkReader,int) (at Assets/Mirror/Runtime/MessagePacker.cs:124)
    13. Mirror.NetworkConnection:UnpackAndInvoke (Mirror.NetworkReader,int) (at Assets/Mirror/Runtime/NetworkConnection.cs:196)
    14. Mirror.NetworkConnection:TransportReceive (System.ArraySegment`1<byte>,int) (at Assets/Mirror/Runtime/NetworkConnection.cs:234)
    15. Mirror.NetworkServer:OnDataReceived (int,System.ArraySegment`1<byte>,int) (at Assets/Mirror/Runtime/NetworkServer.cs:604)
    16. kcp2k.KcpTransport:<Awake>b__13_5 (int,System.ArraySegment`1<byte>) (at Assets/Mirror/Runtime/Transport/KCP/MirrorTransport/KcpTransport.cs:67)
    17. kcp2k.KcpServer/<>c__DisplayClass20_0:<Tick>b__1 (System.ArraySegment`1<byte>) (at Assets/Mirror/Runtime/Transport/KCP/kcp2k/highlevel/KcpServer.cs:192)
    18. kcp2k.KcpConnection:TickAuthenticated (uint) (at Assets/Mirror/Runtime/Transport/KCP/kcp2k/highlevel/KcpConnection.cs:331)
    19. kcp2k.KcpConnection:Tick () (at Assets/Mirror/Runtime/Transport/KCP/kcp2k/highlevel/KcpConnection.cs:372)
    20. kcp2k.KcpServer:Tick () (at Assets/Mirror/Runtime/Transport/KCP/kcp2k/highlevel/KcpServer.cs:243)
    21. kcp2k.KcpTransport:LateUpdate () (at Assets/Mirror/Runtime/Transport/KCP/MirrorTransport/KcpTransport.cs:125)
     
  11. Wraix

    Wraix

    Joined:
    Oct 2, 2012
    Posts:
    4
    I seem to be able to fix it with a null check on the statebuffer on line 1820

    Code (CSharp):
    1. if (stateBuffer[i] != null && stateBuffer[i].ownerTimestamp > teleportState.ownerTimestamp)
     
  12. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @Wraix Good catch, there were a couple minor issues with the teleport like this that have been fixed recently and will be in the next release.
     
  13. Kawalyn

    Kawalyn

    Joined:
    Apr 8, 2015
    Posts:
    14
    Hey,

    first of all thanks for the super useful and helpful tool, saved me a lot of time prototyping my current VR-MP project.

    I just updated the mentioned project to the new MLAPI API to not end up having to do my work twice in a few weeks/months. Sadly my SmoothSyncs are now throwing errors which is to be expected as the MLAPI API changed quite a bit.
    Are you going to update the MLAPI components in the near future, or will i have to find fixes myself/not use SmoothSync for a while?

    Thanks in advance, have a nice week!
     
  14. cpasjuste

    cpasjuste

    Joined:
    Apr 2, 2012
    Posts:
    154
    Hello!

    There is actually a few little bugs in smooth sync that need a workaround (as mentioned here). This is not really convenient, and I think most "fixes" posted here are not really clean and can probably generate other bugs (I think of the state buffer bug for example).

    Do you plan to release an update soon as it's not currently working fine "out of the box". No offense here, i like you work but i (we?) need something solid ! :)
     
  15. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @Kawalyn @cpasjuste an update is coming for both the mlapi stuff and the as-yet unreleased fixes. Sorry for the wait.
     
    Kawalyn, CosmicStud and cpasjuste like this.
  16. cpasjuste

    cpasjuste

    Joined:
    Apr 2, 2012
    Posts:
    154
    Hi @thegreatzebadiah,

    Just to be clear, after reading my post again, I don't won't to put too much pressure. The plugin is so helpful and is (was) working so fine that It became mandatory in my game, that's it :)

    I'm currently blocked because of some random "NaN" vector3 errors as discussed previously here, I'm not sure where they comes from. They can occur very soon in the game, i suspect the teleport function and maybe the "buffer hack" to create some wrong "states" or "corrupt" the buffer states, then when it happens all seems to be "F***ed up" (interpolation is completely out of sync and doing weird things, lots of NaN errors, etc).

    I will try to "investigate" more tomorrow and report. For now, for testing purposes, i did switch to mirror network transform to see if the problem could be somewhere else, but it seems all is working fine with it (but it's far from Smooth Sync result ;) ).
     
    Last edited: Mar 29, 2021
  17. cpasjuste

    cpasjuste

    Joined:
    Apr 2, 2012
    Posts:
    154
    Hi there,

    I was able to find the time to do more testing, and i can confirm the problem seems to comes from the teleport function. If i don't use it, all seems to work fine.

    Edit: after further testing, the problem ("Infinity or NaN floating point numbers appear when calculating the transform matrix for a Collider...") still occur on a "network spawned" prefab, "randomly" (it usually happen after a few network spawns) even when not using smooth sync on this prefab. It seems to only happen from an android build (il2cpp) so i'm not sure anymore why it happen (it could be unity, mirror...). I'll be back later with more informations..

    Edit 2: I was able to find where the problem occurs. I'm instantiating a (network) prefab at a player (hand) position (from server) and after a few one, the position of the player hand (on the server) is NaN (while the position on the clients seems correct). The player use Smooth Sync for position, the source of the problem may still be here. Note that the problem doesn't seems to occurs when the server is run from the editor, but it does when running headless.
    To fix this, for now, i'm setting the initial position from the client instead from server, and all is working fine.
     
    Last edited: Mar 31, 2021
  18. SXtheOne

    SXtheOne

    Joined:
    Sep 5, 2018
    Posts:
    21
    Hi,
    I'm using Mirror 16.9.0 and the current Smooth Sync version is not compiling because of the more recent changes in Mirror networking. Is it possible to get an older Smooth Sync version which is compatible with this Mirror version? If it is possible then how can I get that? :)
     
  19. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @SXtheOne If you message me with your invoice number I can try and get you a version that will work with that version of Mirror.
     
  20. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @cpasjuste I just uploaded the new version to the Asset Store that hopefully fixes the NAN issues. Sorry for the long wait. Glad you found a solution anyway though.
     
    cpasjuste likes this.
  21. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    The latest version that I just uploaded to the Asset Store works with the latest MLAPI. It should be available within a few days.
     
  22. SXtheOne

    SXtheOne

    Joined:
    Sep 5, 2018
    Posts:
    21
    Okay, I sent you a mail, thanks!
     
  23. cpasjuste

    cpasjuste

    Joined:
    Apr 2, 2012
    Posts:
    154
    Thanks @thegreatzebadiah , your work is much appreciated here :)
     
  24. Japsu

    Japsu

    Joined:
    Jan 17, 2018
    Posts:
    14
    Hey!
    Just bought your asset, and it doesn't seem to be fully compatible with the latest MLAPI API, you planning to release a fix soon?
     
  25. Japsu

    Japsu

    Joined:
    Jan 17, 2018
    Posts:
    14
    Nevermind, it seems like your earlier fix just got pushed through by the asset store!
     
  26. cpasjuste

    cpasjuste

    Joined:
    Apr 2, 2012
    Posts:
    154
    Hi,

    Unfortunately the latest version doesn't seems to fix teleport:

    Also, it seems the position on server still get out of sync randomly, i need to do more testing i guess to see where this happen. I maybe did an error somewhere... I think It may be related to additive scene loading, not sure yet.

    Edit: just to confirm, all is working fine when using mirror NetworkTransform.
     
    Last edited: Apr 8, 2021
  27. ZackerLee

    ZackerLee

    Joined:
    Oct 8, 2020
    Posts:
    1
    Hi guy,
    I'm here to wait for your package to be able to support Tnet3 Networking.
    Please let me know if it happens, thanks a lot
     
  28. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @cpasjuste
    Thanks for the update. @thegreatzebadiah has gone on a break from work so he won't be replying for about a week and a half. I wanted to reply to you though so you knew we haven't forgotten about you. :) It sounds like you have a workaround by reading your past posts, but we'll definitely want to put out a real fix. Thank you for letting us know.
     
    cpasjuste likes this.
  29. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @minhtinh
    I'll try to remember to let you know, but Tnet3 support is either reaaaaallly far away, or never coming unfortunately.
     
  30. Hertzole

    Hertzole

    Joined:
    Jul 27, 2013
    Posts:
    422
    Hi there
    Could there be a possibility to add support for Mirage, a fork of Mirror? It unfortunately changes quite frequently but IMO much better than Mirror in many places.
     
    Last edited: Apr 13, 2021
  31. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @RealMTG
    Right now we are keeping our eye on Mirage, but don't have any promises that we'll add drop-in support for it. My biggest issue with Mirror is how often they make sweeping architectural changes. And with what I've heard and seen so far with Mirage, it's more of the same. If they get around to stabilizing Mirage, then it's definitely something I'd want to look into more though. Feel free to reach out again about if they get more stable than Mirror though.
     
    Hertzole likes this.
  32. cpasjuste

    cpasjuste

    Joined:
    Apr 2, 2012
    Posts:
    154
    Hi,

    I'd like to know if anyone is using latest unity (2020.3.x), mirror and smooth sync versions without problems ?

    For me, it's now unusable since a few months, because of two (or one?) problems: the teleport function is crashing randomly (this is not a major problem), and the transform/smooth "states" are "desynchronized" randomly (i suspect it comes from LoadSceneAsync, not sure at all... but it was working fine before the updates), it seems the server (smooth) states are "desync/corrupted".
     
  33. Kawalyn

    Kawalyn

    Joined:
    Apr 8, 2015
    Posts:
    14
    Thanks for the new MLAPI version update, everything working, well, smoothly again :)

    Got a little question/problem though:
    When the host player throws an object in VR it obviously works out of the box as he is the instance that has final control over Transform data. When a client picks up an object and throws it, it immediately drops to the floor as it's not passing its velocity values and therefore the host thinks it should just drop to the floor when gravity re- and isKinematic deactivates.
    I disable the SmoothSync component on my pickup objects when picking them up and then re-enable them when letting go. Would there be an easy way to pass the velocity and angular velocity of the object into SmoothSync when letting go on a client?

    Any help would be highly appreciated, a bit overwhelmed with TODO's at the moment after being ill for a week >.<

    Thanks in advance and a wonderful weekend :)
     
  34. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @cpasjuste
    If it isn't currently running using 2020.3.x Unity and latest Mirror, then we definitely want it to be. Thank you for reporting it. I think I told you already but the main Smooth Sync dev these days is out for the rest of the week but he should be replying early next week and should have a better response for you. Sorry again about the issues.
     
  35. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @Kawalyn
    The main Smooth Sync dev these days is out for the rest of the week but I wanted to reply so you know we got your post. :) He should be responding more fully to you early next week. Thank you.
     
    Kawalyn likes this.
  36. CosmicStud

    CosmicStud

    Joined:
    Jun 13, 2017
    Posts:
    55
    With object pooling, an object which was turned on and spawned, then despawned and turned off. Once turned on again for respawning, will output, how would I reset smoothsync to reinitialize?


    SpawnStateException: Object is not spawned
    MLAPI.NetworkObject.GetObservers () (at Library/PackageCache/com.unity.multiplayer.mlapi@17bd894dff/Runtime/Core/NetworkObject.cs:182)
    Smooth.SmoothSyncMLAPI.sendState () (at Assets/Imported/Dependencies/Smooth Sync/MLAPI/Smooth Sync Asset/SmoothSyncMLAPI.cs:902)
    Smooth.SmoothSyncMLAPI.FixedUpdate () (at Assets/Imported/Dependencies/Smooth Sync/MLAPI/Smooth Sync Asset/SmoothSyncMLAPI.cs:781)


    Before the object is spawned. Just wondering if an, IsSpawned check will work as a fix in the fixedupdate or update?
     
    Last edited: Apr 26, 2021
  37. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    590
    @OnlyTheCosmos
    The main Smooth Sync dev these days has been on vacation but he will be returning in the next day or so. I just wanted to let you know that we have gotten your issue and we will be responding with a better reply shortly. Sorry about the issue.
     
  38. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @OnlyTheCosmos I just tried implementing a simple object pool and I didn't seem to need any special handling for Smooth Sync. My implementation looks like this:

    Code (CSharp):
    1.  
    2. using MLAPI;
    3. using MLAPI.Spawning;
    4. using Smooth;
    5. using System.Collections;
    6. using System.Collections.Generic;
    7. using UnityEngine;
    8. public class MLAPIObjectPool : NetworkBehaviour
    9. {
    10.     public int poolSize = 2;
    11.     public NetworkObject poolObject;
    12.     GameObject[] poolObjects;
    13.     private void Awake()
    14.     {
    15.         poolObjects = new GameObject[poolSize];
    16.     }
    17.     public override void NetworkStart()
    18.     {
    19.         base.NetworkStart();
    20.         // Instantiate objects in pool
    21.         for (int i = 0; i < poolSize; i++)
    22.         {
    23.             poolObjects[i] = Instantiate(poolObject.gameObject);
    24.             poolObjects[i].SetActive(false);
    25.         }
    26.         if (NetworkManager.Singleton.IsClient)
    27.         {
    28.             // Register spawn and despawn handlers on client so they can use the pool
    29.             NetworkSpawnManager.RegisterSpawnHandler(poolObject.PrefabHash, PoolObjectSpawnHandler);
    30.             NetworkSpawnManager.RegisterDestroyHandler(poolObject.PrefabHash, PoolObjectDespawnHandler);
    31.         }
    32.     }
    33.     public void OnDestroy()
    34.     {
    35.         NetworkSpawnManager.UnregisterSpawnHandler(poolObject.PrefabHash);
    36.         NetworkSpawnManager.UnregisterDestroyHandler(poolObject.PrefabHash);
    37.     }
    38.     // Use pool to spawn object on client
    39.     NetworkObject PoolObjectSpawnHandler(Vector3 pos, Quaternion rot)
    40.     {
    41.         GameObject ob = GetObjectFromPool();
    42.         ob.transform.position = pos;
    43.         ob.transform.rotation = rot;
    44.         return ob.GetComponent<NetworkObject>();
    45.     }
    46.     // Return object to pool on the client when it is despawned
    47.     void PoolObjectDespawnHandler(NetworkObject ob)
    48.     {
    49.         ReturnObjectToPool(ob.gameObject);
    50.     }
    51.     // Get an inactive object from the pool and activate it
    52.     GameObject GetObjectFromPool()
    53.     {
    54.         for (int i = 0; i < poolSize; i++)
    55.         {
    56.             if (!poolObjects[i].gameObject.activeSelf)
    57.             {
    58.                 // ---- MAYBE YOU NEED THIS -----
    59.                 poolObjects[i].GetComponent<SmoothSyncMLAPI>().clearBuffer();
    60.                 // ------------------------------
    61.                 poolObjects[i].SetActive(true);
    62.                 return poolObjects[i];
    63.             }
    64.         }
    65.         return null;
    66.     }
    67.     // Return an object to the pool by simply deactivating it
    68.     void ReturnObjectToPool(GameObject ob)
    69.     {
    70.         ob.SetActive(false);
    71.     }
    72.     // On keypress spawn or despawn networked object
    73.     void Update()
    74.     {
    75.         if (NetworkManager.Singleton.IsServer)
    76.         {
    77.             // Spawn an inactive object from the pool on the server
    78.             if (Input.GetKeyDown(KeyCode.P))
    79.             {
    80.                 GameObject ob = GetObjectFromPool();
    81.                 ob.GetComponent<NetworkObject>().Spawn();
    82.             }
    83.             // Despawn an active object and return it to the pool on the server
    84.             if (Input.GetKeyDown(KeyCode.O))
    85.             {
    86.                 for (int i = 0; i < poolSize; i++)
    87.                 {
    88.                     if (poolObjects[i].gameObject.activeSelf)
    89.                     {
    90.                         poolObjects[i].GetComponent<NetworkObject>().Despawn();
    91.                         ReturnObjectToPool(poolObjects[i]);
    92.                         break;
    93.                     }
    94.                 }
    95.             }
    96.         }
    97.     }
    98. }
    99.  
    100.  
    With that implementation I don't get the error you mentioned. You may want that clearBuffer() call but I don't think that's related to the error you're getting at all. Maybe you can rework things based on that object pool implementation and the error will go away. Let me know if you're still having issues.
     
    CosmicStud likes this.
  39. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Generally you would switch ownership to the client when they pick it up, then if another client picks it up switch ownership again. You could also switch back to server ownership if no client interacts with it for some amount of time. If you enable the Smooth Authority Changes option under Miscellaneous category on the Smooth Sync component it will also help the ownership changes be more seamless so that velocity is maintained if the object is moving during ownership change.
     
  40. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    I just released a new version to the Asset Store that should address the teleport issue, which is actually an old issue that I accidentally brought back. It's fixed again now though. Let me know if the update also fixes your desync issues.
     
  41. Der_Kevin

    Der_Kevin

    Joined:
    Jan 2, 2013
    Posts:
    517
    Hey, so i am super new to smooth sync. so pardon me if the questions are weird ;)
    so ive got 2 cubes - one is the host and the other is a client and they should push each other around. the code is fairly simple:

    Code (CSharp):
    1.  if (GetComponent<NetworkIdentity>().hasAuthority)
    2. {
    3.         {
    4.             Control = new Vector3(Input.GetAxis("Horizontal") * .2f, 0, Input.GetAxis("Vertical") * .2f);
    5.             ApplyVelocity(Control * 100);
    6.         }
    7.     }
    8.  
    9.     public void ApplyVelocity(Vector3 force)
    10.     {
    11.         rb.velocity = force;
    12.        // CmdApplyVelocity(force);
    13.  
    14.     }
    but the problem is, it doesn't feel right over the network. it seams the pushed player is always slowing down and you dont get the same physical interaction you have when you play locally. its hard to explain. maybe you also stumbled over that problem and there are some sttings i dont know that makes pushing other players a bit better?
    thanks!
     
  42. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @Der_Kevin You're actually scratching at a pretty deep problem in network syncing there:

    Physical interactions between objects with different owners is pretty tricky. The best way to handle it is usually to have the server control all the objects that need to physically interact with each other. You can either do this by changing the authority of the object so that the server owns it, or you can leave the client as owner but change the Transform Source on the Smooth Sync component to "Server" instead of "Owner."

    Either way the server would then have control of all the objects and they would all be able to interact and collide properly. You then need some way for the clients to tell the server when they want to do something though, since the server controls everything. Usually you would use some rpcs to send commands to the server so it can execute whatever action the player is inputting.

    THEN when you get all that working you'll notice there is an annoying delay for players trying to control their own character because the action has to go all the way to the server to get executed, and then Smooth Sync has to sync the motion all the way back.

    At that point you'll want to look in to something called client-side prediction which essentially fakes the action on the client so that controlling the player feels responsive but the server still maintains ultimate control. Smooth Sync does not implement client-side prediction so that's something you'd need to figure out yourself, the solution tends to be different for every game and could be simple or super complex depending on what you need.

    The simpler solution though is...don't do that. Not every idea that works for local multiplayer will work for networked multiplayer. Take it from someone who worked for years on a networked game where players pull each other around instead of pushing...it's not a great road to go down. That's not to say it's impossible at all, as obviously many games do manage direct physics based interactions between characters with varying levels of success. Just know that you're in for more work than it probably seems like if you really want good consistent interactions. This road has led to people inventing their own deterministic networked physics engines to replace Unity's non-deterministic physics engine and other similarly maddening solutions. If you gaze long into an abyss, the abyss also gazes into you.
     
  43. cpasjuste

    cpasjuste

    Joined:
    Apr 2, 2012
    Posts:
    154
    Hi @thegreatzebadiah,

    Many thanks for the update, it also fixed my "server transforms being out of sync on additive scene loading" (I guess the teleport function I'm now using again on additive scene loading (map change) does fix this).

    This is an awesome news for me, thanks again :)
     
  44. SnooksV3

    SnooksV3

    Joined:
    Dec 11, 2018
    Posts:
    11
    Just bought SmoothSync, Imported and I get this error.

    Assets\Smooth Sync\Mirror\Smooth Sync Asset\SmoothSyncMirror.cs(398,46): error CS0117: 'Channels' does not contain a definition for 'Unreliable'
     
  45. SnooksV3

    SnooksV3

    Joined:
    Dec 11, 2018
    Posts:
    11
    Changed it to DefaultUnreliable and it works. Is this safe?
     
  46. SnooksV3

    SnooksV3

    Joined:
    Dec 11, 2018
    Posts:
    11
    Also, quick question. Does SmoothSync interpolate locally for you?

    I have a fully server authoritative player movement script which gives me jitters while passing moving objects (when I don't use the built in interpolate in Unity). Which makes sense, but I'm wondering if SmothSync fixes that issue?
     
  47. SnooksV3

    SnooksV3

    Joined:
    Dec 11, 2018
    Posts:
    11
    Not sure if I'm doing something wrong or not. Basically my player script is fully server authoritive. On the client the player rigidbody is set to isKinematic
    Welp. I found this post luckily. My Game ->


    I managed to get a pretty smooth game without any interpolation. Everything is great except some movement jitters when close to other objects. I was hoping SmoothSync would fix this. Is SmoothSync still incapable of achieving of this?
     
  48. SixDimensional

    SixDimensional

    Joined:
    Nov 6, 2015
    Posts:
    4
    Hello! I just bought Smooth Sync and it seems to be fighting a script I'm already using with MRTK and the Hololens 2 to network with PUN 2. Both scripts seem to be updating networked position causing a lot of jittering between the two positions.

    This is the script, any ideas on what I would need to replace in this script with Smooth Sync methods to make it work?
    Code (CSharp):
    1. using Photon.Pun;
    2. using UnityEngine;
    3.  
    4. namespace MRTK.Tutorials.MultiUserCapabilities
    5. {
    6.     public class GenericNetSync : MonoBehaviourPun, IPunObservable
    7.     {
    8.         [SerializeField] private bool isUser = default;
    9.  
    10.         private Camera mainCamera;
    11.  
    12.         private Vector3 networkLocalPosition;
    13.         private Quaternion networkLocalRotation;
    14.  
    15.         private Vector3 startingLocalPosition;
    16.         private Quaternion startingLocalRotation;
    17.  
    18.         void IPunObservable.OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    19.         {
    20.             if (stream.IsWriting)
    21.             {
    22.                 stream.SendNext(transform.localPosition);
    23.                 stream.SendNext(transform.localRotation);
    24.             }
    25.             else
    26.             {
    27.                 networkLocalPosition = (Vector3) stream.ReceiveNext();
    28.                 networkLocalRotation = (Quaternion) stream.ReceiveNext();
    29.             }
    30.         }
    31.  
    32.         private void Start()
    33.         {
    34.             mainCamera = Camera.main;
    35.  
    36.             if (isUser)
    37.             {
    38.                 if (TableAnchor.Instance != null) transform.parent = FindObjectOfType<TableAnchor>().transform;
    39.  
    40.                 if (photonView.IsMine) GenericNetworkManager.Instance.localUser = photonView;
    41.             }
    42.  
    43.             var trans = transform;
    44.             startingLocalPosition = trans.localPosition;
    45.             startingLocalRotation = trans.localRotation;
    46.  
    47.             networkLocalPosition = startingLocalPosition;
    48.             networkLocalRotation = startingLocalRotation;
    49.         }
    50.  
    51.         // private void FixedUpdate()
    52.         private void Update()
    53.         {
    54.             if (!photonView.IsMine)
    55.             {
    56.                 var trans = transform;
    57.                 trans.localPosition = networkLocalPosition;
    58.                 trans.localRotation = networkLocalRotation;
    59.             }
    60.  
    61.             if (photonView.IsMine && isUser)
    62.             {
    63.                 var trans = transform;
    64.                 var mainCameraTransform = mainCamera.transform;
    65.                 trans.position = mainCameraTransform.position;
    66.                 trans.rotation = mainCameraTransform.rotation;
    67.             }
    68.         }
    69.     }
    70. }
    71.  
     
  49. Japsu

    Japsu

    Joined:
    Jan 17, 2018
    Posts:
    14
    Hi!
    First of all, let me say that SmoothSync is really godsent for my project. It's awesome, and it's amazing to see that the developer(s) are still actively working on it!

    I used to sync my rigidbodies as client authoritative, but I had some strange behavior with collisions (players clipping inside each other, etc). This steered me towards using a full server authoritative method ( deterministic lockstep in my case ), which I have now fully implemented. This fixed all the wonky behavior with rigidbodies but introduced a whole lot of input lag.

    The only thing that really bugs me with SmoothSync, is the lack of client-side prediction/deterministic rollback (if I'm getting the terms right). I'm meaning client-side simulation, even with SmoothSync Transform source set to server authoritative. Now don't get me wrong, I don't mean that it would be your job to implement it to SmoothSync as the implementation of course differs from project to project.

    However, is there any way you could steer me in the right direction with implementing it to SmoothSync because as far as I know there isn't really any other proper way of "negating" the input lag caused by the message traveling to the server, get checked, and travel back to the player?
    For my project, it's really important to have accurate physics simulations with minimal input lag. The best way I could describe my project is World of Tanks, but with better physics.

    If anybody has additional information or ideas about this, feel free to reach me here or through Discord (Japsu#5434) :)
     
  50. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    Yes this is fine.