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

    SnaiperoG

    Joined:
    Apr 6, 2015
    Posts:
    37
    Yes, there is a new scene, asset store last versions of mirror and smooth sync. Everything in an video. Also i get that objects which going to the plane corners, its a navmesh agent issue, but, on the plane which has thin collider bug visible much more better, and also there is clearly vision that is a extrapolation bug. Idk why its happening even if increase collider size its still present
     
  2. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    526
    @SnaiperoG
    Is the issue that it lags out when your server is at like 5 frames per second like in the video?
    But then it goes back to normal once you stop lagging on the server?

    That is just going to happen probably. It's probably sending a bunch of weird jittery updates with the server looking like it's at ~5 frames per second there.
    But it should go back to normal once the Server FPS gets to a more reasonable amount.

    The reason for this is probably extrapolation as you are probably only getting a couple states per second when it's expecting much more. So it gets its one position, then doesn't get another one for like .3 seconds when it's expecting 30 a second. So it assumed the server is having issues (which seems to be true) so it goes into extrapolate mode and lets physics take over.
    You can maybe turn extrapolation off and have it not fall over like it is though.

    Also don't forget SnapTimeThreshold should be .3 This won't fix your issue while going into 5fps server mode, but it will help once your server gets back to a more normal FPS so I just wanted to say it again. :)
     
    Last edited: Dec 22, 2020
  3. SnaiperoG

    SnaiperoG

    Joined:
    Apr 6, 2015
    Posts:
    37
    ok, got the reason, but i have same thing happents on production build. Im developing a mobile fps game and some users have same flickering enemies, even with dedicated server. I will let you know when i will catch it, because now i cant. All i know for now is that change from smoothsync to networktransform solved the problem
     
  4. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    526
    @SnaiperoG
    If you haven't changed the SnapTimeThreshold to .3 yet in the build you have for other players, then that is the most likely cause of that. Download the latest Smooth Sync and set SnapTimeThreshold to .3 and I believe it'd go away. Let me know if it doesn't.
     
  5. emrys90

    emrys90

    Joined:
    Oct 14, 2013
    Posts:
    669
    How well does this work for VR grabbing objects where the physics can't all be owned by the same client? IE most things owned by the server, but it needs to switch to the local client when a player grabs an object or something
     
  6. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    526
    @emrys90
    It works well.

    From our Asset Store page:
    "Smooth Authority Changes (UNet/Mirror/MLAPI)
    Perfect for VR for when you need to change authority to local when handling objects."

    Let me know if you have any questions.
     
  7. harleydk

    harleydk

    Joined:
    Jul 30, 2012
    Posts:
    35
    Hi @Fuestrine, I had the same issue - @cpasjuste 's response was very helpful. Would you consider adding it to the next version?
    So glad I bought this asset - invaluable. Happy New Year.
     
  8. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    526
    @harleydk
    Seems reasonable to me if someone else has also had the same issue. I'll bump up the priority a bit and see if I can look at it and implement it before next release. Thanks for letting me know about it.
     
  9. Samb88

    Samb88

    Joined:
    Mar 26, 2009
    Posts:
    204
    Hey @Fuestrine !
    Small thing for using this plugin with Mirror:
    SmoothSyncMirror.cs always subscribes to the clientAutjprotyCallback Event but never unsubscribes.
    This is a bit annoying, since I'm using non SmoothSync objects with changing player authority and the "AssignAuthorityCallback" function will always trigger the "Smooth Sync: Cannot find target for authority change" errormessage. And because it never unsubscribes it fires the message even for objects, that are already destroyed.

    A simple
    Code (CSharp):
    1. public void OnDestroy()
    2. {
    3.             NetworkIdentity.clientAuthorityCallback -= AssignAuthorityCallback;
    4. }
    solves the problem in SmoothSyncMirror, but it would be even better, if smooth sync would not fire this message for every authority change that is happening. Was a bit confused why smooth sync was sending an error on a object, that doesn't use smooth sync :)
     
    harleydk likes this.
  10. harleydk

    harleydk

    Joined:
    Jul 30, 2012
    Posts:
    35
    I believe I have identified a bug in SmoothSync. In as 'the problem goes away if I use the standard Mirror NetworkTransform'.

    I have a smooth-sync'ed object inside an inactive gameobject. When this inactive gameobject is made active, and the smooth-synced object becomes visible, I get the following exception when I attempt to move it:

    Exception in MessageHandler: NullReferenceException Object reference not set to an instance of an object at Smooth.SmoothSyncMirror.getPosition () [0x00021] in <e7da2fb2372c4fce8d67f97005096933>:0
    at Smooth.StateMirror.copyFromSmoothSync (Smooth.SmoothSyncMirror smoothSyncScript) [0x0000c] in <e7da2fb2372c4fce8d67f97005096933>:0

    If I use the regular ole' NetworkTransform, this error goes away.
     
  11. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    526
    @Samb88
    Good catch! I should be able to get this into the next release. Thanks for letting me know about it. :)
     
    Samb88 likes this.
  12. mrstinkyweasle

    mrstinkyweasle

    Joined:
    Nov 2, 2020
    Posts:
    4
    OK I have a query and hopefully someone can help!

    I have a game where a player can spawn xx dice (1, 2 or even 10 dice). these can then be moved around in 3d space as if held in a hand. What's the best way of syncing these? I've tried all sorts so far with various degree's of success. My latest attempt is parenting them all to a single object with multiple smoothsyncs to control the child dice, but really struggling to add these components at run time (because I dont know how many the player will choose to spawn). I've also tried adding a controller to each dice to check mouse position and move the dice to that location with an offset so it doesnt clang into other "held" dice, but this appeared jerky on the other client.
     
  13. harleydk

    harleydk

    Joined:
    Jul 30, 2012
    Posts:
    35
    @mrstinkyweasle 10 spawned objects with their own SmoothSync-component should surely work. Jerkiness may go away if you change 'TransformSource' to server (instead of 'Owner'), then again maybe not, could be caused by many other things. But simply defaulting to letting them have each their SmoothSync's - consider heavily leaning on the many options & maybe simply syncing position - should work fine.
     
  14. mrstinkyweasle

    mrstinkyweasle

    Joined:
    Nov 2, 2020
    Posts:
    4
    @harleydk Maybe I’m going about something very wrongly! Every update (or fixed update, I’ve tried both) I get position on the client and move the transform position of each dice accordingly. They all have a rigid body with kinematic set to true by default so they don’t just start dropping. When the player is ready they click and kinematic is disabled for their versions and physics takes over. I had hoped that just syncing position then would do the job and it does seem to for the most part. I’ve tweaked lots of the settings but nothing quite does the job.
    It’s smooth as silk with two windowed local versions running. Going over the wire though this goes jerky. Maybe I just need to adjust my expectations of what’s possible
     
  15. OnlyTheCosmos

    OnlyTheCosmos

    Joined:
    Jun 13, 2017
    Posts:
    29
    Awesome, thanks for your amazing work!
     
    harleydk likes this.
  16. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    526
    @harleydk
    Are you up to date on the latest Smooth Sync? If not, try the latest.
    I'll stick the issue on my list to look into. Thanks for letting me know about it.
    As a quick fix, changing the following methods into what I have below will probably get you by:
    Code (CSharp):
    1. /// <summary>Get position of object based on if child or not.</summary>
    2.         public Vector3 getPosition()
    3.         {
    4.             if (realObjectToSync == null || realObjectToSync.transform == null)
    5.             {
    6.                 return positionLastFrame;
    7.             }
    8.  
    9.             if (isSyncingChild || useLocalTransformOnly)
    10.             {
    11.                 return realObjectToSync.transform.localPosition;
    12.             }
    13.             else
    14.             {
    15.                 return realObjectToSync.transform.position;
    16.             }
    17.         }
    18.         /// <summary>Get rotation of object based on if child or not.</summary>
    19.         public Quaternion getRotation()
    20.         {
    21.             if (realObjectToSync == null || realObjectToSync.transform == null)
    22.             {
    23.                 return rotationLastFrame;
    24.             }
    25.  
    26.             if (isSyncingChild || useLocalTransformOnly)
    27.             {
    28.                 return realObjectToSync.transform.localRotation;
    29.             }
    30.             else
    31.             {
    32.                 return realObjectToSync.transform.rotation;
    33.             }
    34.         }
    35.         /// <summary>Get scale of object.</summary>
    36.         public Vector3 getScale()
    37.         {
    38.             if (realObjectToSync == null || realObjectToSync.transform == null)
    39.             {
    40.                 return lastScaleWhenStateWasSent;
    41.             }
    42.  
    43.             return realObjectToSync.transform.localScale;
    44.         }
     
  17. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    526
    @mrstinkyweasle
    I wouldn't be spawning children of Smooth Sync objects and reparenting at runtime as that's not really officially supported. Calling SmoothSync.Awake() should alleviate some problems with that though.

    One reason for your jerky movement might be that you are moving the dice on both the owner and non-owner. You will only want to move them on the owner since Smooth Sync will handle all movement on non-owners. I'd confirm the owner is who you think it is of your dice.

    Are you using Smooth Sync default settings? Try default settings if not.
    If it's Smooth locally but not over the network, maybe you are experiencing a higher network latency or latency variance than expected. Try raising Smooth Sync's InterpolationBackTime variable to like 2 seconds and it might confirm this. Either way I'd ping your systems and see what the latency looks like. I'd also confirm your FPS.

    If that fails, take a look at the example scene provided by Smooth Sync for your networking system and see how it might be different than yours.
    Let me know how it goes.
     
  18. harleydk

    harleydk

    Joined:
    Jul 30, 2012
    Posts:
    35
    Thanks @Fuestrine for your support. I can confirm I'm on the latest version.

    I incorporated your code - thanks. For what it's worth, the issues seems to originate here,

    Exception in MessageHandler: NullReferenceException Object reference not set to an instance of an object at Smooth.SmoothSyncMirror.addTeleportState (Smooth.StateMirror teleportState) [0x00042] in <6c23ae7fdf9547bcbbf4699f8b0d833e>:0
    at Smooth.SmoothSyncMirror.UserCode_CmdTeleport (UnityEngine.Vector3 position, UnityEngine.Vector3 rotation, UnityEngine.Vector3 scale, System.Single tempOwnerTime) [0x00046] in <6c23ae7fdf9547bcbbf4699f8b0d833e>:0
    at Smooth.SmoothSyncMirror.InvokeUserCode_CmdTeleport (Mirror.NetworkBehaviour obj, Mirror.NetworkReader reader, Mirror.NetworkConnectionToClient senderConnection) [0x00034] in <6c23ae7fdf9547bcbbf4699f8b0d833e>:0
    at Mirror.RemoteCalls.RemoteCallHelper.InvokeHandlerDelegate (System.Int32 cmdHash, Mirror.MirrorInvokeType invokeType, Mirror.NetworkReader reader, Mirror.NetworkBehaviour invokingType, Mirror.NetworkConnectionToClient senderConnection) [0x00020] in <9e3216e869d34538b4e2581a9ddf6d9c>:0
    at Mirror.NetworkIdentity.HandleRemoteCall (System.Int32 componentIndex, System.Int32 functionHash, Mirror.MirrorInvokeType invokeType, Mirror.NetworkReader reader, Mirror.NetworkConnectionToClient senderConnection) [0x00089] in <9e3216e869d34538b4e2581a9ddf6d9c>:0
    at Mirror.NetworkServer.OnCommandMessage (Mirror.NetworkConnection conn, Mirror.CommandMessage msg) [0x000fa] in <9e3216e869d34538b4e2581a9ddf6d9c>:0
    at (wrapper delegate-invoke) System.Action`2[Mirror.NetworkConnection,Mirror.CommandMessage].invoke_void_T1_T2(Mirror.NetworkConnection,Mirror.CommandMessage)
    at Mirror.MessagePacker+<>c__DisplayClass6_0`2[T,C].<WrapHandler>b__0 (Mirror.NetworkConnection conn, Mirror.NetworkReader reader, System.Int32 channelId) [0x000e7] in <9e3216e869d34538b4e2581a9ddf6d9c>:0
     
  19. harleydk

    harleydk

    Joined:
    Jul 30, 2012
    Posts:
    35
    @Fuestrine Further in regards to the issue, I can see that it's caused in the addTeleportState() function, because the 'stateBuffer' object is null.
    I'm guess this is because the Awake() function is never called because the object is originally hidden, and when it's set to active again the object has never been initialized.

    A 'regular active' SmoothSync'ed object behaves impeccably.
     
    Last edited: Jan 9, 2021
  20. hugopok

    hugopok

    Joined:
    Mar 30, 2016
    Posts:
    42
    Hi guys, i am developing a fast paced game (top down shooter) i need to sync with Smooth sync pun 2 the movement and the rotation, i have 2 scripts, one attached to the main object which move the gameobject, and the other attached to the body which rotate the gameobject, what are the best settings to have a transform as smooth as possible ?
     
  21. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    526
    @harleydk
    I could see that happening. Thanks again for the details!
    You should be able to throw a
    if (stateBuffer == null || stateBuffer[0] == null) return;
    at the beginning of that method as a quick fix.
     
  22. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    526
    @hugopok
    The Smoothest settings would probably be the default. But if you want it faster paced, you'll probably want to lower the InterpolationBackTime but keep it above 1/SendRate or you may see jitter from extrapolating too much. You may also be able to increase the LerpSpeeds (maybe called EasingSpeeds these days) to 1 without issue.
     
  23. hugopok

    hugopok

    Joined:
    Mar 30, 2016
    Posts:
    42
    Thank you, i will let you know, and i post the result here :)
     
  24. hugopok

    hugopok

    Joined:
    Mar 30, 2016
    Posts:
    42
    I am sorry what do you mean with "1/SendRate" ?
     
  25. hugopok

    hugopok

    Joined:
    Mar 30, 2016
    Posts:
    42
    @Fuestrine
    Ok i think to understand, for instance if i have setted the send rate to 30, my interpolationBackTime should be 1/30 = 0.03, what i don't understand is the time correction speed, what is supposed to do ?
     
  26. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    526
    @hugopok
    Yep 30 send rates can handle .03 InterpolationBackTimes. May want to bump it to .04 if you see jitter from extrapolating too much but it might be fine.
    I'd keep TimeCorrectionSpeed at the default value of .1. You can maybe increase it, but it'll get jittery pretty quickly.
     
  27. harleydk

    harleydk

    Joined:
    Jul 30, 2012
    Posts:
    35
    Hello @Fuestrine, I've been trying to dig deeper into this.

    So, there're two SmoothSync'ed objects. One visible from the start, the other inside an inactive game-element.

    Awake() is called for the visible one, no problem. I works perfectly in every respect.

    The inactive game-element, inside of which is the second SmoothSync'ed object, is then made visible. This triggers a spawn of the object, which in turn calls its Awake(). Same as the other one. So the stateBuffer[] is initialized (the calculatedStateBufferSize is 8, with both objects).

    Yet when the addTeleportState() method is called, the stateBuffer is NULL. I've incorporated your suggestion and am returning from that function, but an exception is still thrown - apparently the stateBuffer[] is in use elsewhere, but I have not the wherewithall to see where, it's quite dense code and, y'know, when it's not your code-base...

    So I'm pretty stumped on this one, and could use a hand. As I mentioned, with the regular ol'e NetworkTransform from Mirror it works without problems.

    This is not a high-priority matter - I won't be getting to distribute my app until the Covid-19 vaccine has been properly distributed (it's a VR game that is played with 4 students in the same physical space).
     
  28. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    526
    Version 3.32 has just been released.

    Change log:
    • Removed AssignAuthorityCallback in OnDestroy() in Mirror version.
    • Changed SnapTimeThreshold default to be lower.
    • Reset example scene variables back to default.
     
    harleydk likes this.
  29. PieterAlbers

    PieterAlbers

    Joined:
    Dec 2, 2014
    Posts:
    191
    Hi! Thanks for the great asset!

    I really am happy with our results so far (carcombat game). We're using PUN2 and syncing position and rotation on a rigidbody. This works fine for us under the current circumstances.

    However, it seems I am unable to get syncing working for velocity and angular velocity.
    I checked all settings and they're all default. We don't reset or override the (angular)velocity ourselves either.

    Syncing for both angular- and velocity is set to XYZ. WhenToUpdateTransform has been set to FixedUpdate.

    What could be going on? What could I be missing?

    -PIeter
     
  30. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    526
    @PieterAlbers
    Those variable headings may be confusingly named. The velocity and angular velocity doesn't get set on the non-owner end because it would cause a bit of jitter when fighting the position setting. They are just used to better handle extrapolation.
    I thought I explained this in the mouse over text of those variables but it looks like I didn't. Thanks for letting me know about the confusion I caused.

    You should be able to go in and grab the velocities from the targetTempState in ApplyInterpolationOrExtrapolation() if you need them for something though.
     
    PieterAlbers likes this.
  31. PieterAlbers

    PieterAlbers

    Joined:
    Dec 2, 2014
    Posts:
    191
    No worries, I was able to workaround it. I did some digging but not very far - couldn't find any setting on non-owners but I guessed I was missing something somewhere.

    Agree on not using velocity and angular velocity next to position setting. Noticed some odd behaviour there as well when using or old solution.

    Thanks again for the great asset and reply!
     
  32. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    835
    @harleydk Maybe you can show me some code or explain in more detail. I'm particularly curious about:

    How exactly is that occurring? Generally you don't really want your networked objects to be children of non-networked objects. For this sort of setup your parent object should have the network identity and Smooth Sync script, with the child set as the "Child Object To Sync." This way instead of the parent object being "made visible," which sounds like a local thing, the parent object should instead be spawned so that it is properly network activated everywhere (including clients that join later).

    I'm not really sure if I'm totally understanding the issue though, if you can show me some code it might help.
     
  33. GreenRanchGames

    GreenRanchGames

    Joined:
    Dec 18, 2020
    Posts:
    9
    Hi @Fuestrine,

    I'm using Smooth Sync in a PUN2 game where each player controls an active ragdoll (puppetmaster). I have a script set up which loops through all the rigidbodies in the ragdoll and enables the Smooth Sync component on each one when the player loses balance. It then disables the component when he regains balance to save bandwidth.

    It works as intended, except for one small issue. Whenever the ragdoll is set to sync again, it appears that for one frame the ragdoll will sync to the position is was most recently synced to (the position where the sync was last disabled) - and then snap to the new location and begin functioning normally.

    Are there any possible workarounds to this issue? Any guidance would be appreciated. Thanks!!
     
  34. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    835
  35. harleydk

    harleydk

    Joined:
    Jul 30, 2012
    Posts:
    35
    It is, you're right, a local thing. Some of my gameobjects - those with networked object inside - have unique Guids and I use a mirror client-rpc to set it active i.e. visible on all clients. When I use the regular NetworkTransform, any Mirror-object is spawned upon that 'setting active'. The same SmoothSync'ed object spawns, but immediately breaks the game when I try to pick it up i.e. transfer authority to the client.
    Your comment about avoiding nested networked objects made me think of a different way I could accomplish my goal. I'll pursue that option instead. Thanks @thegreatzebadiah for your attention in this matter.
     
  36. Morseliot

    Morseliot

    Joined:
    Jan 10, 2015
    Posts:
    51
    Hi @thegreatzebadiah , at first, thank you for the great mutliplayer syncing solution. We've experiencing the issue with PUN2 sync. At some point, during the game (might take around 30 minutes), one of the players start moving in an odd way. Local player moves alright, but remote player kind of teleporting itself within some range, if local stop, remote also stop in the same position where the local is, but if local move again, remote will perform teleport within around 3-4 meters and then move smooth (but from the point of teleported position*), and if local stops again, the remote teleport back to the position where local is. We're able to catch out this type of exception, it might be somehow related to the issue. Could you please take a look and give us any suggestions regarding proper setup for the characters to avoid unexpected behaviour.
     
    Last edited: Jan 22, 2021
  37. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,667
    @Fuestrine @thegreatzebadiah Since I have an authoritative server now using Mirror, I'm having some steer/input lag on my vehicles turning which is rather noticeable and something I'd definately like to minimise.

    You can see a screenshot of my settings here...
    https://prnt.sc/xs9pfw

    I've tried playing around with 'Rotation Easing Speed', but can't really get anything satisfactory, the truck wheels turn, and the vehicle turns slightly, but then seems to overcorrect/oversteer when it get's the packets back from the server.

    Doing steer on the client-side physics helps a little but, but the delay is still very noticeable.

    Do you have any suggestions on what I could do to minimise this?

    Thanks
     
  38. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    835
    It sounds like it may be related to time resetting since it only happens after a long time. I'll look in to it and the NAN things as well.

    You may also just need to update, as those line numbers don't seem to line up with the latest code.
     
    Morseliot likes this.
  39. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    835
    For server authoritative you really need client side prediction to cover up the latency for the owner, which is not a feature that Smooth Sync offers, so you'll have to solve that part on your own unfortunately.

    You can probably get somewhat better results by lowering your interpolation back time. You can go all the way down to 0, it's just a trade off between response time and accuracy of syncing. Generally you'll want to keep it above 1/SendRate.
     
    Meltdown likes this.
  40. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,667
    Oh man, that actually works! I ended up putting interpolation backtime to 0.1, which gives me the best results, wow I can't believe how smooth everything feels right now. Definately brings out the Smooth in SmoothSync!

    Thanks again for your amazing asset!
    Not quite sure where I'd be without it tbh.
     
  41. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,667
    @thegreatzebadiah I am struggling to get the rotation/steer of the front tyres on my truck synced across the network.

    I have read the doc here on syncing a child object.
    http://grabblesgame.com/smoothsync/

    I have SmoothSync setup on my parent object, and I added a second SmoothSync, and I set it to the tire I have highlighted in this screenshot.
    https://prnt.sc/xsq77m

    Any idea what I'm doing wrong?

    Thanks
     
  42. Morseliot

    Morseliot

    Joined:
    Jan 10, 2015
    Posts:
    51
    Hi, thanks for advice, I'll try to update. In addition, is it alright that smoothsyncPun2 does have childObjectToSync variable visible in inspector only in debug mode?
     
  43. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    835
    @meltdown It seems like you would want to sync the wheel not the tire, since I assume that is what is rotating.
     
  44. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    835
    @Morseliot PUN2 doesn't use childObjectToSync, instead you put the Smooth Sync component on the actual child. You can see how it's done in the example scene, specifically the SmoothSyncPlayerPrefabPUN2 prefab.
     
    Morseliot likes this.
  45. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,667
    I don't understand, the tire is the mesh/model/texture being rotated by the wheel script. If I sync just the tyre mesh that is being rotated across the network, then surely its transform's rotation should be synced to the tire meshes across the other clients? We are syncing transforms after all?

    Does there need to be anything on the tire/wheel object, i.e perhaps a NetworkIdentity/NetworkTransform or something else?
     
  46. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    835
    @Meltdown I guess I misunderstood what is being rotated. If the tire is the GameObject whose rotation you want to sync then it looks like you've got it set up correctly. You should only need one NetworkIdentity on the parent.

    You mention meshes and textures though, if your wheel script is simulating rotation by doing something with the mesh vertices or texture coordinates then Smooth Sync isn't going to sync that. It will only sync the actual Rotation property of the Transform component.
     
  47. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,667
    I'm only trying to sync the rotation of the tire transform, so yeah, no idea why it wouldn't work if it's setup correctly then :(
     
  48. Twyker_gp

    Twyker_gp

    Joined:
    Dec 4, 2018
    Posts:
    29
    Hi!
    Can you tell us how the data being sent is reduced? or rather: how many messages per second does it send?
    I think the regular View sends 10 msgs / second on discrete, is this still true for smooth sync?
    Can we adjust the send rate via SmoothSync directly?

    How does Smooth Sync work with Photon's Animation View?
    Thanks!
     
    Last edited: Feb 3, 2021
  49. GreenRanchGames

    GreenRanchGames

    Joined:
    Dec 18, 2020
    Posts:
    9
    Hi there - I wrote the following script to attach a player character to a platform that moves through the air. It changes the parent object of the player to the platform object when triggered, and unparents it when exited. The player's movement is synced using a SmoothSyncPUN2. The platform itself is a Photon instantiated scene object, and there was significant jittering of the character as I assume the network syncing of the non-owned player is battling the syncing of the platform it is parented to.

    I decided to try having the SmoothSyncPUN2 use only local transforms, as you can see below, but this causes non-owned players to move to world coordinates 0, 0, 0, and the parenting to platform no longer works. The script works normally for your own player on your own machine. Hoping for any suggestions, thank you!

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. using GameCreator.Characters;
    6. using Photon.Pun;
    7. using Smooth;
    8.  
    9. public class PlatformAttach : MonoBehaviourPun
    10. {
    11.     public PlayerCharacter player;
    12.  
    13.     private Transform originalParent;
    14.     private Transform attachToMe;
    15.  
    16.     private void Start()
    17.     {
    18.         originalParent = player.transform.parent;
    19.     }
    20.  
    21.     private void OnTriggerEnter(Collider other)
    22.     {
    23.         if (!other.tag.Equals("Attachable")) return;
    24.  
    25.         //Attach to this default transform (a child of the platform) to avoid issues with scaling
    26.         attachToMe = other.transform.Find("AttachToMe").transform;
    27.        
    28.         if(photonView.IsMine)
    29.         {
    30.             photonView.RPC("AttachRPC", RpcTarget.All);
    31.         }
    32.        
    33.     }
    34.  
    35.     private void OnTriggerExit(Collider other)
    36.     {
    37.         if (!other.tag.Equals("Attachable")) return;
    38.  
    39.         if (photonView.IsMine)
    40.         {
    41.             photonView.RPC("DetachRPC", RpcTarget.All);
    42.         }
    43.  
    44.     }
    45.  
    46.     [PunRPC]
    47.     private void AttachRPC()
    48.     {
    49.         player.transform.parent = attachToMe;
    50.         player.GetComponent<SmoothSyncPUN2>().useLocalTransformOnly = true;
    51.     }
    52.  
    53.     [PunRPC]
    54.     private void DetachRPC()
    55.     {
    56.         player.transform.parent = originalParent;
    57.         player.GetComponent<SmoothSyncPUN2>().useLocalTransformOnly = false;
    58.     }
    59.  
    60. }
    61.  
     
  50. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    835
    @Meltdown I'm really not sure what the issue could be. If your project is small enough you could send it to me at the support email UnitySupport@noblewhale.com and I can poke around in it. If the project is not small or not well organized you could try recreating the issue in a fresh project and sending me that. I suspect that if you try to recreate the issue in an isolated environment you will discover what is going wrong. That's usually how it goes.
     
unityunity