FishNet icon indicating copy to clipboard operation
FishNet copied to clipboard

[PRO] NetworkTransform syncs position before syncing the changed parent (2.5.1)

Open AhonenAJ opened this issue 3 years ago • 2 comments

Currently NetworkTransform.GetChanged does this:

if (parentBehaviour != null)
	changed |= ChangedDelta.Nested;

but that's checking the value from _lastSentTransformData instead of the current parent, which causes the object's position to jump around when the local position syncs before the parent does. Changing it to this fixes the issue for me:

if (_parentBehaviour != null)
	changed |= ChangedDelta.Nested;

AhonenAJ avatar Sep 26 '22 12:09 AhonenAJ

Can you tell me how to reproduce please. EG: start host, client auth NT, ect.

FirstGearGames avatar Sep 26 '22 17:09 FirstGearGames

I have a player object with a server-authoritative NT and parent syncing enabled. In my scene, there's a platform object that has a network behaviour so I can parent the player to that. Now, if I start a host and another client and make the host toggle (eg. by a keypress or whatever) its player object's parenting between the platform and null, then, on the client, the player warps to the wrong position briefly because the local position syncs (one tick?) before the parenting change does. Of course the platform should be placed so that the local position changes for the player object when the parenting changes.

AhonenAJ avatar Sep 27 '22 10:09 AhonenAJ

I reviewed your recommendation and it does make sense to make those changes. Thanks for debugging that. I left that particular method the same though and changed this one instead. It may look like extra lines of code but it's compiled inline.

Changes will be in 2.6.1.

        private ChangedDelta GetChanged(TransformData transformData)
        {
            /* If parent behaviour exist.
            * Parent isn't sent as a delta so
            * if it exist always send regardless
            * of the previously sent transform
            * data. */
            NetworkBehaviour parentBehaviour = _parentBehaviour;
            return GetChanged(ref transformData.Position, ref transformData.Rotation, ref transformData.Scale, parentBehaviour);
        }

FirstGearGames avatar Nov 16 '22 22:11 FirstGearGames