Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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. foolmoron

    foolmoron

    Joined:
    Jun 22, 2013
    Posts:
    30
    I tried a bunch of things and nothing really got rid of the initial catch up lag. Higher FORCE_TIME_SYNC_DURATION, higher timeCorrectionSpeed, lower snapTimeThreshold, nothing quite did it. I don't really get what's going on in this function I guess.
     
  2. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @foolmoron
    I've got the issue narrowed down on my end. It's because that FORCE_SYNC goes off only once on the server when a client joins if the client doesn't move. The issue isn't seen on clients(at least not the way I'm testing). Then by the time the client actually moves, it's done forcing the time change so it just slowly adjusts.

    I've got a fix in now where I keep automatically setting the new time for an amount of received States equal to a ratio of the SendRate, but I'm going to need to look at it again when I wake up to be certain.
     
    Last edited: Nov 5, 2018
  3. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    Version 3.08 has been submitted to the Asset Store.

    Change log:
    • Fixed issue with slow time correction at beginning on server when client doesn't move initially.
    • Smooth Authority Changes fix for all uses.
    • Fixed 2D rigidbody not working with velocity driven syncing.
     
  4. Richie_V

    Richie_V

    Joined:
    Dec 3, 2014
    Posts:
    3
    Hello, I just would like to say I would be also interested in Mirror support, I am working on a LAN only project using Smooth Sync, and Mirror is the best solution I've found for that, and unlike PUN, or the upcoming Unity Networking solution, Mirror is open source and free to host, so just to add to the suggestion, maybe it is worth it to support the simplest truly free solution out there with your asset :)
     
  5. the_dunderman

    the_dunderman

    Joined:
    May 4, 2017
    Posts:
    4
    Hey Fuestrine,

    We are a small team working on a prototype for a networked version of our developed local multiplayer game using PUN2. We were having jittering issues, and decided to use your asset to smooth things out.

    I have been tweeking settings on the smooth sync script in our test scene for the past 3 days, and I am having some seemingly unsolvable issues. It is easy enough to smooth our players for non-master clients using your script. All our issues are with physics based objects in the scene that can be affect by either player, and thus are server owned. As you can imagine, our master client sees a perfect simulation of the objects being interacted with, as it does all of the physics calculations for the photon server.

    One example of a big issue we're having is with a stack of cubes (with an empty parent) that the players can crash into. When we use the smooth sync script, we can get a pretty smooth and accurate interaction with a non-master client if we check the "Use Velocity Driven Syncing" box under misc. However, this causes the cube to, what we're calling, "melt" on the non-master clients screen. The boxes slowly drift away from each other on the non-master clients scene, but on the master-clients scene, they are perfectly still. If either player hits the cubes, they teleport back to the position they should be, and then accurately simulate the rigidbodies being hit.

    Our player (also with an empty parent) has "Use Velocity Driven Syncing" checked, and the issue with this is sometimes the positions aren't synced on player screens.

    Why is this happening when we check this box? Shouldn't transform positions still be synced while also trying to affect velocities of an object? Why are they not synced, and in completely different places on the screen until they are interacted with (Our Photon Views are set to "Unreliable")? I saw that for UNET parent objects also require your script. I'm not sure if this is true for PUN2, and if it is, how should we be configuring these settings? How should parent and child versions of your script differ if it is required to attached them in both places?

    We also have a lot of "rope" like objects in our game, which are a bunch of fixed joints attached to one another. We are having trouble between non-master client and rope interaction using the settings that work for the cubes, but there is no "melting" for the rope.

    Any tips or answers to my endless amount of questions, or even just one, I think would help. Let me know if you need any more info to help answer any of these as well.

    Thanks,
    Matt
     
    utkarshdwivedi3997 likes this.
  6. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @the_dunderman
    Thanks for bringing it to my attention. It looks to be a problem with at rest when using the VelocityDrivenSyncing.

    I'll have to make a cleaner version and take a deeper look at it this weekend, but changing the else if code block that starts on line 868 of SmoothSyncPUN2.cs to this solved the issue for me.
    Code (CSharp):
    1. else if (stateBuffer[0].atPositionalRest && stateBuffer[0].atRotationalRest)
    2. {
    3.                 targetTempState.copyFromState(stateBuffer[0]);
    4.                 extrapolatedLastFrame = false;
    5.                 if (setVelocityInsteadOfPositionOnNonOwners) triedToExtrapolateTooFar = true;
    6.             }
    I didn't need to change MaxPositionDifference (underneath UseVelocityDrivenSyncing) for the fix but it should make it more accurate overall if you lower that.

    You may also be getting extrapolation issues, try turning extrapolation off if the above code doesn't fix it.

    I don't think there are any issues with them being children or not. You just need a SmoothSync on each object you want to sync, child or not, with the way Photon works I believe.

    Let me know how it goes, if you have any questions, or if I missed anything.
     
    Last edited: Nov 10, 2018
    the_dunderman likes this.
  7. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @Richie_V
    Fine, you've all convinced me to take a deeper look at it. :)
    I've been seeing it around online a bit lately too.

    I'm not promising anything but I'll take a better look at a conversion and see how it would be for me to put out releases.
     
    Last edited: Nov 10, 2018
    Richie_V likes this.
  8. iStolyarov

    iStolyarov

    Joined:
    Oct 29, 2018
    Posts:
    3
    Hi! I have two problem if i use plugin with Photon (PUN V1) on Unity 2018.2.13f1:
    1. If i add Smooth Sync PUN (Script) to GameObject i have a Error and object not synced.
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEngine.Networking.NetBuffer.ReadByte () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkBuffer.cs:33)
    3. UnityEngine.Networking.NetworkReader.ReadByte () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkReader.cs:160)
    4. Smooth.NetworkStatePUN.Deserialize (UnityEngine.Networking.NetworkReader reader, Smooth.SmoothSyncPUN smoothSync) (at Assets/!IMPORTED/Smooth Sync/Other Networking APIs/PUN/Smooth Sync Asset/StatePUN.cs:440)
    5. Smooth.SmoothSyncPUN.OnPhotonSerializeView (PhotonStream stream, PhotonMessageInfo info) (at Assets/!IMPORTED/Smooth Sync/Other Networking APIs/PUN/Smooth Sync Asset/SmoothSyncPUN.cs:2028)
    6. PhotonView.ExecuteComponentOnSerialize (UnityEngine.Component component, PhotonStream stream, PhotonMessageInfo info) (at Assets/!IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:532)
    7. PhotonView.DeserializeComponent (UnityEngine.Component component, PhotonStream stream, PhotonMessageInfo info) (at Assets/!IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:378)
    8. PhotonView.DeserializeView (PhotonStream stream, PhotonMessageInfo info) (at Assets/!IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:363)
    9. NetworkingPeer.OnSerializeRead (System.Object[] data, PhotonPlayer sender, System.Int32 networkTime, System.Int16 correctPrefix) (at Assets/!IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:4399)
    10. NetworkingPeer.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/!IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2631)
    11. ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (System.Byte[] inBuff) (at <f525be5a15db43b28dff4016d8fa9620>:0)
    12. ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands () (at <f525be5a15db43b28dff4016d8fa9620>:0)
    13. ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () (at <f525be5a15db43b28dff4016d8fa9620>:0)
    14. PhotonHandler.Update () (at Assets/!IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:161)
    15.  
    upload_2018-11-12_11-56-31.png
    2. If i use Smooth Sync (Script) my GameObject after load the GameScene throw the error but, if i enabled the gameobj in Editor script work fine.
    Code (CSharp):
    1. The observed monobehaviour (Player - Basic(Clone)) of this PhotonView does not implement OnPhotonSerializeView()!
    2. UnityEngine.Debug:LogError(Object)
    3. PhotonView:ExecuteComponentOnSerialize(Component, PhotonStream, PhotonMessageInfo) (at Assets/!IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:544)
    4. PhotonView:DeserializeComponent(Component, PhotonStream, PhotonMessageInfo) (at Assets/!IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:378)
    5. PhotonView:DeserializeView(PhotonStream, PhotonMessageInfo) (at Assets/!IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:363)
    6. NetworkingPeer:OnSerializeRead(Object[], PhotonPlayer, Int32, Int16) (at Assets/!IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:4399)
    7. NetworkingPeer:OnEvent(EventData) (at Assets/!IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2631)
    8. ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[])
    9. ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
    10. ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
    11. PhotonHandler:Update() (at Assets/!IMPORTED/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:161)
    12.  
     
    Last edited: Nov 12, 2018
  9. mrmirhajian1996

    mrmirhajian1996

    Joined:
    Sep 18, 2018
    Posts:
    1
    great asset. I am using it to create a motorcycle race game,but there is an issue.
    when motorcycle 1 overtake motorcycle 2 in host, the motorcycle 1 overtake motorcycle 2 after one or even two seconds in client. what fields should i change ? what am i doing wrong ?
     
  10. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @mrmirhajian1996
    Lower your InterpolationBackTime probably. It puts it this far back in time on purpose.

    Keep in mind that if your InterpolationBackTime is less than your SendRate/100 (sendRateOnSerialize in photon?) then you will be extrapolating a bit between every received message.

    Let me know if this doesn't fix your issue.
     
  11. katasteel

    katasteel

    Joined:
    Nov 21, 2014
    Posts:
    161
    So I just got the newest version of SmoothSync and I see you made the teleport function need Local Authority at some point.

    What about things like projectiles from monsters which have no local authority?

    Teleport needs to be used when using object pooling.
     
  12. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @katasteel
    I think that's always been the case. I don't know how you would send a message if you don't have authority and Smooth Sync has never used separate objects to send messages around.

    The monster's (EDIT: projectile) local authority would be the server if it isn't owned by any non-server clients, unless I'm completely misunderstanding something.

    Let me know if I'm misunderstanding or if you have further questions.
     
    Last edited: Nov 13, 2018
  13. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @iStolyarov
    I'm seeing the same thing on my end. Sorry about the PUN issue and thanks for bringing it to my attention. It's being very tricky to track down though, I'll have to take another look at it tomorrow and get back to you.
     
    Last edited: Nov 13, 2018
  14. the_dunderman

    the_dunderman

    Joined:
    May 4, 2017
    Posts:
    4
    @Fuestrine

    Thanks so much for the answer. We took a dive into the code and it stopped our "melting" issue. I also set the local rigidbody component's velocity and angular velocity to Vector3.zero in that if statement you suggested to us.

    One thing we found was an if block that didn't run correctly because you had an new if statement for your 2D rigidbody check rather than an "else if", which caused the else statement to run every time for us since we are using 3D rigidbodies. This was in SmoothSyncPUN2 around line 1350-1360, and our new code looked as followed (just changed the second if to an else if)

    Code (CSharp):
    1. if (hasRigidbody && !isTeleporting && whenToUpdateTransform == WhenToUpdateTransform.FixedUpdate)
    2. {
    3.     rb.MovePosition(position);
    4. }
    5. else if (hasRigidbody2D && !isTeleporting && whenToUpdateTransform == WhenToUpdateTransform.FixedUpdate)
    6. {
    7.     rb2D.MovePosition(position);
    8. }
    9. else
    10. {
    11.      realObjectToSync.transform.position = position;
    12.      DebugTransformChange();
    13. }
    We do have a new issue though, and maybe this isn't smooth sync related, but right now our clients "bounce" off of other rigidbodies that the master client has no issue affecting. What I mean by this is our player has a mass of 10, and we have a stack of cubes that are no longer melting at a mass of 1. Our master client will barrel through and knock the cubes over, but our normal client will hit the stack, bounce off, and affect the cubes as if the normal client barely hit the stack.

    Almost none of the options for SmoothSync seem to alleviate the issue here.

    Have you faced this problem before? Do you believe it to be an issue with SmoothSync, or rather our PUN connection in general?

    We took off smooth sync and just used the normal PhotonView for Rigidbody, and this issue isn't present. Any input would be helpful.

    Thanks again,
    Matt
     
  15. katasteel

    katasteel

    Joined:
    Nov 21, 2014
    Posts:
    161
    It's calling teleport on the server from an object that does not have authority and gets a warning and never teleports because of this:

    Code (CSharp):
    1.             if (!hasAuthority)
    2.             {
    3.                 Debug.LogWarning("Trying to teleport from an unowned object. You can only teleport from an owned object. Look up Unity networking object ownership.");
    4.                 return;
    5.             }
     
  16. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @katasteel
    You'll need to call it on the owned object. Owned objects have hasAuthority == true. I don't know of any way to send a message from an unowned object. It goes against how UNet works unless I'm misunderstanding something.

    Let me know if I'm missing something or if you have further questions.
     
  17. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @iStolyarov
    Alright, I believe this will fix the issue. Sorry again and thanks for letting me know about it.

    I'll be cleaning up the code for release but here's the fix: Replace this with the OnPhotonSerializeView in SmoothSyncPUN.

    Code (CSharp):
    1. bool sentMessage = false;
    2.         public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    3.         {
    4.             // When sending data.
    5.             if (stream.isWriting)
    6.             {
    7.                 // Determine if and what we should send.
    8.                 sendState();
    9.                 if (shouldSendNextPUNUpdate)
    10.                 {
    11.                     sentMessage = true;
    12.                     stream.SendNext(sentMessage);
    13.                     NetworkWriter netWriter = new NetworkWriter();
    14.                     sendingTempState.Serialize(netWriter);
    15.                     // Sending the serialized byte array
    16.                     stream.SendNext(netWriter.AsArray());
    17.                     shouldSendNextPUNUpdate = false;
    18.                 }
    19.                 else
    20.                 {
    21.                     sentMessage = false;
    22.                     stream.SendNext(sentMessage);
    23.                 }
    24.                 // Set variables for use next frame.
    25.                 positionLastFrame = getPosition();
    26.                 rotationLastFrame = getRotation();
    27.                 // Reset flags back to default.
    28.                 resetFlags();
    29.             }
    30.             // When receiving data.
    31.             else
    32.             {
    33.                 bool receivedSmoothMessage = (bool)stream.ReceiveNext();
    34.                 if (receivedSmoothMessage)
    35.                 {
    36.                     NetworkStatePUN networkState = new NetworkStatePUN(this);
    37.                     //if (stream.Count > 0)
    38.                     {
    39.                         // Receiving the byte array
    40.                         object objectTemp = stream.ReceiveNext();
    41.  
    42.                         Byte[] byteArray = objectTemp as Byte[];
    43.                         NetworkReader netReader = new NetworkReader(byteArray);
    44.                         networkState.Deserialize(netReader, this);
    45.  
    46.                         if (networkState != null && !photonView.IsMine)
    47.                         {
    48.                             networkState.smoothSync.addState(networkState.state);
    49.                         }
    50.                     }
    51.                 }
    52.             }
    53.         }
    Let me know how it goes.
     
  18. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @the_dunderman
    Nice catch on the elseif issue. Thanks! I'll put it in the next update.

    For the physics interaction between separate owners questions, it's expected behavior. Games that have important physics (like rocket league) will have the physics objects all be owned by the server. The reason PhotonRigidbodyView works for this is because it doesn't work in many other ways, like hitting an unowned object so that it becomes nowhere near where it should be.

    I think you can get SmoothSync to act more like PhotonRigidbodyView though, but it's not a real solution as the hits will be more random than if objects owned by the same machine were to collide. Try turning your InterpolationBackTime down. You may want to turn your SendRate(PhotonNetwork.serilizationRate?) up so you aren't extrapolating too much, but also extrapolation will probably help you collide more. You will get extraplation if you lower your InterpolationBackTime to be less than your SendRate/100.

    My understanding of why separate owner physics isn't good:
    Say you collide a moving sphere (owned by a client) with a stationary cube (owned by the server). The cube is being told to sit still by the server since the the server determines the cube's position. So from the client's view, the sphere is rolling into a brick wall. The sphere never goes into a position that would have it collide with the cube, it just goes to a position that is exactly contacting it, which is nothing like fully rolling into a cube.

    Maybe something to try, but it's probably bad:
    If you take out the AtRest 0 velocity fix I sent earlier, I think it may react more, but that was completely unintentional as the owner is the only one that should be determining the object's position. Maybe try a low MaxPositionDifference and take out the AtRest 0 fix.

    Let me know if that helps or if I was confusing in any of that.
     
    Last edited: Nov 15, 2018
  19. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @katasteel
    Oh yeah. I wanted to say what you should do to get a message to the owner of an object.

    So if you have an object on the server that is owned by a client but you want to use the server to tell it to teleport, you'd send a message over on an object that the server owns. Typically a Game Controller or something similar would be server owned and may be useful for something like this. Then, the client receives this message and will tell it's owned object to teleport.
     
    Last edited: Nov 14, 2018
  20. iStolyarov

    iStolyarov

    Joined:
    Oct 29, 2018
    Posts:
    3
    @Fuestrine Hi again, i fix ussue by dettaching Photon Transform View and RigidBodyView and you script at PUN work without any modification, but unfortunatly if players interactions by using RigidBody2D.AddForce() (this action send and recieved similar as just in time, but character bad sync position) or move fast i have some problem:
    1. Sometime player fall in the collider and return if player who control the character jump or do something
    2. The character lags behind
    May be i incorrect setup script or do something wrong, i wait for you responce. I want to sync physics actions in my game.
    My setup for your script:
    upload_2018-11-14_18-48-18.png
     
  21. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @iStolyarov
    Can you word this differently? I'm not understanding what you are saying. Any idea on how to recreate the issue so I can see it on my end? I don't see anything in your Smooth Sync settings that is wrong.

    Lower the InterpolationBackTime if you want the object to be less in the past. Right now it is .12s in the past on purpose because of the InterpolationBackTime. Keep in mind that with the default 10 SendRate of Photon, if you put InterpolationBackTime below .1, you will be extrapolating consistently.
     
    Last edited: Nov 14, 2018
  22. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    Version 3.09 is on the Asset Store.

    Changes:
    -Fixed issue with disconnecting and reconnecting while in the same scene with networked scene objects not registering handlers.
    -Fixed PUN and PUN2 not syncing when there were multiple network observed components.
    -Fix for VelocityDrivenSyncing staying at rest when supposed to.
    -SetPosition() now does rigidbody.MovePosition() if it has a rigidbody and WhereToUpdate is FixedUpdate.
     
    Last edited: Nov 15, 2018
  23. iStolyarov

    iStolyarov

    Joined:
    Oct 29, 2018
    Posts:
    3
    Hello again! I fix last ussue and smoe time later have new one.
    I have 2 player the first isMasterClient and second client, on scene has a ball with SmoothSynPUN, both of this player playing with this ball by touching their colliders and if client touch ball he do not have any reactions, but this fixed by ChangeOwner and this helps.
    But at the moment on ChangeOwner ball have seriosly desync (laggy).
    Player's and the ball have RigidBody2D with SmoothSyncPUN.
    I mean you have simple solution for this case but i dont find this.
     
  24. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @iStolyarov
    Yeah, the best way to do physics interaction is to have everything owned by the server all the time. A game like Rocket League will have the cars and the ball owned by the server.

    Plenty of games change ownership though, and for that you'll need to call SmoothSync.clearBuffer() on all non-owner instances when the owner changes.

    This reminds me that I don't have a super easy way for PUN to handle ownership changes yet. I'm unable to test this until Friday but try this for a simple way:

    Add this and call clearStateBuffer() on the new owner. It will then automatically send the message across to all non-owners to clear the buffer. It works just like teleport().

    Code (CSharp):
    1. public void clearStateBuffer()
    2.         {
    3.             if (!photonView.isMine)
    4.             {
    5.                 Debug.LogWarning("Trying to send RPC from an unowned object.");
    6.                 return;
    7.             }
    8.             photonView.RPC("RpcClearBuffer", PhotonTargets.Others);
    9.         }
    10.         [PunRPC]
    11.         public void RpcClearStateBuffer()
    12.         {
    13.             clearBuffer();
    14.         }

    Let me know if you have further questions.
     
    Last edited: Nov 22, 2018
  25. foolmoron

    foolmoron

    Joined:
    Jun 22, 2013
    Posts:
    30
    Hmm I have a ball that I change ownership on between players frequently, and I never have to call clearBuffer(). Is it not noticeable at low latencies?
     
  26. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @foolmoron
    If you start your game instances at around the same time it might not be noticeable since the Times will be close to the same on everyone, but you'll want to clearBuffer() for real world scenarios.

    Also with UNet you may have SmoothAuthorityChanges checked which will clear the buffer automatically and smooth from the current position to the new owner's first sent position.

    If you are using SmoothAuthorityChanges, how's it working out for you? I wasn't really sure if the smoothing would be better or if teleporting would be better on ownership changes for scenarios like yours.
     
    Last edited: Nov 22, 2018
  27. katasteel

    katasteel

    Joined:
    Nov 21, 2014
    Posts:
    161
    So this is how I got it working(for anyone having the same problem).

    For standard projectiles(Ones that only travel in one direction).
    I just used the standard network transform syncing on rigid body with send rate 0. I used object pooling for these ones as well.

    But for advanced projectiles that rotate or change direction mid flight I used smooth sync and no object pooling.

    The main problem was if I used smooth sync with the object pooling.
    It would error out because the object was not yet enabled on the client, but smooth sync was trying to send it a network message.
     
  28. Hummy91

    Hummy91

    Joined:
    Jun 7, 2017
    Posts:
    13
    Has anyone ever encountered the 'Unknown message ID 32765 connId: 1' Error? I can't figure out what's causing it because it's not popping up consistently, seemingly at random, it will appear just once when a client connects, other times not at all. At first I thought its fine because I could consistently make it up pop up when a client connects to a host who has 'ragdolled' prior to any client connection, so I thought I had an idea of what was causing it but it seems to be far more random.
     
  29. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @Hummy91
    How are you spawning your objects? The message is always right after spawning?
     
  30. Hummy91

    Hummy91

    Joined:
    Jun 7, 2017
    Posts:
    13
    @Fuestrine NetworkServer.SpawnWithClientAuthority() called inside a Command sent by a localPlayer.
    And yes, always after spawning/connecting with a client. The error only occurs on the client that connects, not the first connected client but the second.
    Not sure if related but during match making tests, i'm running into client connection timeout errors for no obvious reason as the client and host were both active. The matchmaking room is still running for the host but seemingly invisible in the match maker (after the timeout error), this might be a separate issue as I haven't had a chance to look into it today. Just mentioning it in case.

    Update: Didn't have much time to do my own debugging/testing yesterday, seems I don't get the error at all when using no transform syncing components and also if I use UNets provided network transform/child transform, no errors. So it's only when using smooth sync.

    My network code at the moment is pretty basic, consisting of the spawn function I mentioned above for a players character object. Which is called via a 'player identity' object that is created automatically by my network manager.

    I also have this tiny addition to my network manager which I'm suspicious of when considering the cause of the error in question.

    Code (CSharp):
    1.     public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId){
    2.         base.OnServerAddPlayer(conn, playerControllerId);
    3.         foreach( NetworkInstanceId id in PlayerNetwork_Manager.Players.Keys ) {
    4.             PlayerNetwork_Manager.Players[ id ].UpdateCharacterObjectID();
    5.             PlayerNetwork_Manager.Players[ id ].UpdatePosition();
    6.         }
    7.     }
    PlayerNetwork_Manager points to a dictionary of players which they register to via OnStartClient().

    The two additions to OnServerAddPlayer are both running commands on the PlayerIdentity which also call an RPC each. The first is to update the reference to the corresponding spawned character object on all PlayerIdentities on all clients.

    The update position is done so that when a client connects, all instances of other players on that client are moved to their position using their top level transform, rather than allowing a network transform sync component to do this. This is because any sync component i've tried would break the joints and ragdoll components of my character prefab when it connects as it only moves/syncs a single rigidbody in a complex setup of joints and bodies. So when a client would connect, if other players were even moderately far from the clients spawn position, this would cause irreparable physics and joint problems.

    This is pretty much the extent of my networking at the moment as I started again from scratch a few days ago.

    Update2: Upon looking into it further, could smooth sync be unhappy because I am directly moving a rigidbody/transform that it is supposed to be syncing? The transform in question is my 'main movement body' which is synced via a SmoothSync component in the child field. I move this transform( and all others in my character prefab ) to their starting local positions in the function i posted above, after moving the top level transform to the position they should be at. This is only done once on client connect/server add player, or at least should only be done once to avoid physics janking out.
     
    Last edited: Nov 26, 2018
  31. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @Hummy91
    You moving it shouldn't be causing any Unknown Message issues I would think.

    I'm not seeing any issues on my end but maybe I've got something different or there's a timing issue with more stuff going on.

    Is there any way I can get you to PM me your project so I can fully test your situation out? Let me know how to recreate the issue in your project if you do.
     
  32. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    Version 2.10 is now on the Asset Store.

    Changes:
    • Added teleportAnyObjectFromServer() method to make teleporting easier.
    • Fix for smoother No Extrapolation objects at rest.
     
    Last edited: Nov 27, 2018
  33. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @katasteel
    I'm still not sure exactly what your problem was and it looks like it's solved, but it got me thinking and I have added an easier way to teleport from the server. You now just need to call teleportAnyObjectFromServer() and it will teleport any object from the server and you won't have to worry about authority since it's the server.

    Let me know if you have any questions.
     
  34. foolmoron

    foolmoron

    Joined:
    Jun 22, 2013
    Posts:
    30
  35. jdcart23

    jdcart23

    Joined:
    Jan 17, 2018
    Posts:
    8
    Hi, I bought your asset a few days ago, and I'm having trouble with clients that have FPS cameras, all of these objects have local authority. When I add the smooth sync component and as you move around, the view of the player vibrates constantly on the local view, this doesn't seem to happen on the remote players. It seems strange to me that this happens on the local view, since they have local authority and these components shouldn't affect them in any way other than getting their current transform and sending it to every other client/server. Do you have any idea on how can I fix this?

    Please let me know if I'm not clear on my question and I'll be happy to elaborate more.

    Thanks!
     
  36. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @jdcart23
    Yeah, Smooth Sync shouldn't be changing position on anything except objects you don't own (except when you specifically call TeleportAnyObjectFromServer(position, rotation, scale)).

    My best guess is that you might have your camera owned by Computer1 while the player it is following is owned by Computer2 and you are watching all of this on Computer3. You'll want your camera owned locally under most circumstances.

    I would confirm that the authority is set up the way you think it is with hasAuthority == true.

    What do you mean this doesn't seem to happen on remote players? You only see it vibrate when moving the host's player around on the host?
     
  37. jdcart23

    jdcart23

    Joined:
    Jan 17, 2018
    Posts:
    8
    The owner of the camera, and the only one that has authority over the movement is the local player. I was using Unity's network transform for the synchronization and it worked perfectly, except for the jittery movement. I'm 99% sure my local client has authority over the object, and therefore owns the camera, since this is the "Player" prefab assigned in the network manager. However, I will do as you advice and check if hasAuthority returns true.

    What I mean is that I don't see any jitter/vibration on the remote clients as they move, I only see the jitter/vibration when I'm on the local player looking through the FPS camera.
     
  38. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @jdcart23
    That definitely seems strange. I don't see any issues with the camera following a local player in the example scene (camera as a child of the player) but the camera isn't as free flowing as a typical FPS setup.

    One other idea may be your camera updating in FixedUpdate() but your player is moving in Update() (or vice versa). Make them both move in the same update and see how it goes.

    If you still get the issue, is there any way you can send me your project in a PM? It's probably the fastest way to get to the bottom of this.
     
    Last edited: Dec 4, 2018
  39. hmpublic2000

    hmpublic2000

    Joined:
    Mar 5, 2018
    Posts:
    7
    Player: Character Controller with component: SmoothSync
    Moving Platform: Move by animation with component: SmoothSync

    Everything goes smooth except when player stand on the moving platform and become child of the platform, the player jigger and somehow not sync between different clients. Tried to switch off player's SmoothSync when on the platform and switch it on again when start moving, the situation become even worse, please help and thanks :)
     
  40. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @hmpublic2000
    One way would be making the player a child on every instance and turning off Smooth Sync on every instance of the player. Then you would unchild it and turn Smooth Sync back on.

    Another way would be to only make the player a child on the owner and have SmoothSync handle the position changes on non-owners.

    Let me know if neither of those helps.
     
  41. hmpublic2000

    hmpublic2000

    Joined:
    Mar 5, 2018
    Posts:
    7
    Unluckily both not works.... keep figuring out the way for resolving this...
     
  42. jdcart23

    jdcart23

    Joined:
    Jan 17, 2018
    Posts:
    8
    @Fuestrine Another thing that I didn't mention is that some of these players are controlled different. There are PC players, that use keyboard and mouse to navigate, and I can definitely try to change where the update happens on these players. However, there are players that are controlled by a VR HMD and I can't control where Update happens on those devices. I will try to change the update setting on the smooth sync and see if that helps, though.

    I still just don't understand why the smooth sync would affect my local players if they have authority, they shouldn't be affected at all.

    Unfortunately I can't share the project with you, but I might be able to create a sample project that reproduces the problem. I will get back to you with that.

    Thanks!
     
  43. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @hmpublic2000
    I just tested with the SmoothSync example scene and only making the player a child on the owner and having SmoothSync handle the position changes on non-owners works for me.

    I see an issue with scale with that solution though, but I don't see any jitteryness. The scale issue is because once you make it a child, the scale changes locally so it sends the new scale over and since it's not a child on the remote non-owners, it puts the local child scale as the global scale. Turn off scale syncing if you don't sync scale.

    Code (CSharp):
    1. if (hasAuthority)
    2.         {
    3.             if (Input.GetKeyDown(KeyCode.P))
    4.             {
    5.                 child.transform.parent = parent.transform;
    6.             }
    7.             if (Input.GetKeyDown(KeyCode.U))
    8.             {
    9.                 child.transform.parent = null;
    10.             }
    11.         }
    Is how I make it the parent and not parent on the owner. The only thing I did with SmoothSync is turn off scale syncing. Let me know how it goes.
     
    Last edited: Dec 4, 2018
  44. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @jdcart23
    Yeah, it shouldn't be affecting local players, but you can add some debug into setPosition() or setRotation() and see if it's happening on the owner. If it is then I'm really confused though.

    Yeah, see if you can get an example scene running with your character controller / camera setup and send it to me because I'm completely lost on why this would be happening with SmoothSync as the issue. You may have a setup I haven't seen before though.
     
  45. hmpublic2000

    hmpublic2000

    Joined:
    Mar 5, 2018
    Posts:
    7
    @Fuestrine
    Truly appreciated to your efforts.
    I believe yes the parent-child positioning should be okay, my concern is once player start moving the child (with CharactorController) with connection to the parent.... , I will keep fighting and again really thanks for your feedback :)
     
  46. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @hmpublic2000
    I'm not seeing any issues with moving the child on the owner either, whether the player has a rigidbody or just moving the position directly around. But I'm just parenting two simple balls together, I'm not sure what your character controller may be doing.

    One other thing to maybe keep in mind, keep your InterpolationBackTime larger than your sendRate / 100 to always interpolate. InterpolationBackTime being too low will cause extrapolation and may cause some jumpiness if you change directions a lot. Let me know if you have further questions.
     
    hmpublic2000 likes this.
  47. jdcart23

    jdcart23

    Joined:
    Jan 17, 2018
    Posts:
    8
    @Fuestrine I apologize, the behavior that I was seeing on the FPS camera running on the PC clients wasn't related to your assets at all. On the other hand, on the players with the VR HMD, the vibration is not visible anymore. Not sure what the problem was, but is not there anymore, so probably isn't related in any way to your assets either. Thanks for your help!
     
  48. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @jdcart23
    Awesome, glad to hear it's not Smooth Sync. If you enjoy the asset and the support I give, every 5 star review helps us get noticed a bit more. :) Let me know if you have any other issues.
     
  49. hmpublic2000

    hmpublic2000

    Joined:
    Mar 5, 2018
    Posts:
    7
    @Fuestrine thanks.
    in your source code once it said:

    // If you need to change ownership of a SmoothSync object you can check Smooth Authority Changes on Smooth Sync
    // It will send an extra byte from server to clients but it will be smooth and automatic.

    May I have any sample code/doc so i can refer to - using SmoothSync to change some gameObject's ownership? Like holding and then throwing out by a player? Thanks.
     
  50. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    284
    @hmpublic2000
    I should probably change the comment a little bit, thanks for the tip.

    Check Smooth Authority Changes and then change authority like normal in Unity.

    Here's one way to switch authority from connection 1 to connection 0:
    Code (CSharp):
    1. someObject.GetComponent<NetworkIdentity>().RemoveClientAuthority(NetworkServer.connections[1]);
    2. someObject.GetComponent<NetworkIdentity>().AssignClientAuthority(NetworkServer.connections[0]);
     
    Last edited: Dec 7, 2018
    hmpublic2000 likes this.