NetworkTransform Allows Objects to Desync
General Unity version: 6000.0.48f1 Fish-Networking version: 4.6.9R Pro Discord link: https://discord.com/channels/424284635074134018/1034477094731784302/1387399779004448858 ** Above, post a link from our Discord where you troubleshot the issue (on Discord click the three dots next to the message, then Copy Message Link). Issue may be closed out if this is not included.
Description Rigidbodies (or slow moving transforms) which move slowly can completely desync between the client and server.
There's three parts to this issue:
- I think the GetChanged function is comparing the change between ticks when it should compare the change since the last frame it sent the clients. I haven't confirmed this, but it is consistent with the behavior I'm seeing.
- The change threshold should be configurable in the NetworkTransform component UI.
- This is more of a feature request, but I think for the rigidbody component configuration it would make sense to use the rigidbody sleep state to determine if updates should be sent rather than a physical change.
Replication Steps to reproduce the behavior:
- Add a Sphere from the 3D objects, and add a rigidbody component to it. Disable gravity.
- Add the NetworkTransform + NetworkObject component. Set component configuration to Rigidbody and uncheck "client authoritative".
- Create a script which adds gravity to the rigidbody every tick. This forces the rigidbody to be 'awake' all the time, allowing for very small changes in movement.
- Put the sphere on top of a very slight ramp.
- Observe the scene over time and see the Sphere become desynced between the client and server.
Expected behavior The NetworkTransform should not allow objects to desync. When the Rigidbody Component Configuration is selected, it would be nice to have the option for the NetworkTransform to use the Rigidbody sleep state to determine if it needs to send changes.
Screenshots
I believe this is the offending section of code.
From what it looks like, the easiest solution would be to allow the user to change the movement detection threshold, which should be available in the next release.
Glad to hear that's coming in the next release. I still think it's important to ensure the object doesn't gradually desync over time too though.
If you check the rigid body sleep state before checking the threshold, you ensure the rigid body movement is captured accurately. If you just check the threshold against the last state sent to the client, the object will only get movement updates every few ticks. This could cause choppy movement but maybe the interpolation/extrapolation could cover for that.
I was able to reduce the frequency of the desynchronizing by making my own sleep script. But my game is a sandbox game, and no matter what I set a custom threshold too, the user could still make an object which moves slow enough to not get synchronized. For my use case accurate positioning is important.
Added in 4.6.10.
You can manually adjust your current NT by looking for >= 0.001f in the source and lowering the value to whatever you like (but not 0f or less).
Does the just include the adjustable movement threshold or also the issue of the transform desynchronizing? Again, any value other than 0 could result in a desync based on my observations.
Does the just include the adjustable movement threshold or also the issue of the transform desynchronizing? Again, any value other than 0 could result in a desync based on my observations.
It doesn't compare against current position, it compares against last sent.
I guess that's not the cause of the issue then, but the desynchronizing I'm seeing is far more than the threshold. So I'm not sure how it's possible if this data is checked correctly. Have you tried to replicate the issue?
I guess that's not the cause of the issue then, but the desynchronizing I'm seeing is far more than the threshold. So I'm not sure how it's possible if this data is checked correctly. Have you tried to replicate the issue?
I just tried with a different but similar setup and was not able to reproduce.
Here is the sample package.
- Open scene 930 in two editors.
- Start as host or server only in Editor1.
- Start as client in Editor2.
See object update to the correct position roughly every 2 seconds. I'm going to update labels.
Modify as needed please, and let me know what changes you made.
Here is the demo I ran which demonstrates the issue, I'll look at the one you attached and see if I can get similar behavior. I didn't include Fishnet in the unitypackage so you will need to import it for the demo to run.
You will need to wait for a couple minutes to start seeing the desync. Thanks!
(Edit was to make it so the forces only get added on the server but that did not fix the issue)
Interestingly I haven't been able to replicate the issue on the project you sent, at least within the set up you provide.
I must have missed the reply notifications as I'm just now seeing this.
Have you tested on 4.6.10 yet?
I will try that this evening, did you observe the desync in my demo?
I did not see the update until I was logging off for the day. I would have given it a try but you said it could take several minutes, and you already know what to look for, so I figured if you can confirm that the issue still exist I can look into it.
On Fri, Jul 18, 2025, 1:57 PM Derek Lore @.***> wrote:
Midnight-Sink left a comment (FirstGearGames/FishNet#930) https://github.com/FirstGearGames/FishNet/issues/930#issuecomment-3090244018
I will try that this evening, did you observe the desync in my demo?
— Reply to this email directly, view it on GitHub https://github.com/FirstGearGames/FishNet/issues/930#issuecomment-3090244018, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGPJC3TOJ6GWJZVK5BTV4XL3JEYR5AVCNFSM6AAAAACAELNZSGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTAOJQGI2DIMBRHA . You are receiving this because you commented.Message ID: @.***>
The issue is still present on 4.6.12R Pro
Gotcha. Please leave detail step by step guide on how to use your demo scene.
See our creating a big report guide for information.
Elaborate on 'a few minutes' please.
On Sat, Jul 19, 2025, 10:58 AM Derek Lore @.***> wrote:
Midnight-Sink left a comment (FirstGearGames/FishNet#930) https://github.com/FirstGearGames/FishNet/issues/930#issuecomment-3092394958
The issue is still present on 4.6.12R Pro
— Reply to this email directly, view it on GitHub https://github.com/FirstGearGames/FishNet/issues/930#issuecomment-3092394958, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGPJC3Q57J4EZ44TN55C77T3JJMKPAVCNFSM6AAAAACAELNZSGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTAOJSGM4TIOJVHA . You are receiving this because you commented.Message ID: @.***>
How to Set Up the Demo:
- Open the Demo Scene
- There will be errors because fishnet is not installed in the project. Import the Fishnet unity package. (4.6.12R Pro)
- Multiplayer Play Mode should already be in the project. If not, install it using the package manager window.
- Click the 'Default' dropdown next to the play mode button. Select 'TwoPlayer', or if that option is not there, create a two player play mode configuration.
- Press play. This should launch another instance of the demo and play demo in the editor.
- Start server and client on one of the instances, and on the other just start the client.
- Observe the physics interactions become out of sync. This happens early on but becomes most noticeable after a minute of two, when the balls move at slower velocity.
What You are Seeing in the Demo:
- There are 6 blue balls in the scene, these have custom gravity applied every tick.
- The one red ball in the scene uses normal gravity.
- The green ramp with a transparent box on it defines a custom gravity zone. The gravity when objects enter the zone is changed to match the downward direction of the transform of the ramp.
- The long yellow box on the bottom of the screen has a very shallow decline in refence to the spheres on the right side.
- The custom gravity scripts are located in the Demo folder.
What will Desync:
- On the long yellow ramp at the bottom of the screen, the blue ball will very slowly roll down the ramp, but only on the server. The client never sees the blue ball move.
- On the green ramp (gravity zone), when the three balls from the shorter yellow ramp impact the balls in the gravity zone, you can see them noticeably correct their positions on the client when the impacts occur.
- After the collisions 3 balls will be left on the green ramp, slowly rolling. After a couple minutes the balls will be very desynced, with one of them rolling off of the green ramp. When that balls rolls off there is a noticeable correction on the client side. The other balls on the client side remain desynced.
Sorry for the delay -- there's been a lot going on. Reports will be getting reviewed again in the near future.
Thanks, please update when you try the demo
Thanks, please update when you try the demo
Issue confirmed and easily noticed! This is the current task being worked on.
Issue found. Will have this resolved soon.
Fixed in 4.6.13.
in NetworkTransform.cs do the following:
Add this method to class TransformData
internal void SetIsDefaultToFalse() => IsDefault = false;
Change void SerializeChanged to this
private void SerializeChanged(ChangedDelta changed, PooledWriter writer, TransformData dataToUpdate = null)
{
bool canUpdateData = dataToUpdate != null;
if (canUpdateData && changed != ChangedDelta.Unset)
dataToUpdate.SetIsDefaultToFalse();
UpdateFlagA flagsA = UpdateFlagA.Unset;
UpdateFlagB flagsB = UpdateFlagB.Unset;
/* Do not use compression when childed. Depending
* on the scale of the parent compression may
* not be accurate enough. */
TransformPackingData packing = ChangedContains(changed, ChangedDelta.Nested) ? _unpacked : _packing;
int startIndexA = writer.Position;
writer.Skip(1);
//Original axis value.
float original;
//Compressed axis value.
float compressed;
//Multiplier for compression.
float multiplier = 100f;
/* Maximum value compressed may be
* to send as compressed. */
float maxValue = short.MaxValue - 1;
Transform t = _cachedTransform;
/* Position. */
if (_synchronizePosition)
{
AutoPackType localPacking = packing.Position;
//PositionX
if (ChangedContains(changed, ChangedDelta.PositionX))
{
original = t.localPosition.x;
if (canUpdateData)
dataToUpdate.Position.x = original;
compressed = original * multiplier;
if (localPacking != AutoPackType.Unpacked && Math.Abs(compressed) <= maxValue)
{
flagsA |= UpdateFlagA.X2;
writer.WriteInt16((short)compressed);
}
else
{
flagsA |= UpdateFlagA.X4;
writer.WriteSingle(original);
}
}
//PositionY
if (ChangedContains(changed, ChangedDelta.PositionY))
{
original = t.localPosition.y;
if (canUpdateData)
dataToUpdate.Position.y = original;
compressed = original * multiplier;
if (localPacking != AutoPackType.Unpacked && Math.Abs(compressed) <= maxValue)
{
flagsA |= UpdateFlagA.Y2;
writer.WriteInt16((short)compressed);
}
else
{
flagsA |= UpdateFlagA.Y4;
writer.WriteSingle(original);
}
}
//PositionZ
if (ChangedContains(changed, ChangedDelta.PositionZ))
{
original = t.localPosition.z;
if (canUpdateData)
dataToUpdate.Position.z = original;
compressed = original * multiplier;
if (localPacking != AutoPackType.Unpacked && Math.Abs(compressed) <= maxValue)
{
flagsA |= UpdateFlagA.Z2;
writer.WriteInt16((short)compressed);
}
else
{
flagsA |= UpdateFlagA.Z4;
writer.WriteSingle(original);
}
}
}
/* Rotation. */
if (_synchronizeRotation)
{
if (ChangedContains(changed, ChangedDelta.Rotation))
{
if (canUpdateData)
dataToUpdate.Rotation = t.localRotation;
flagsA |= UpdateFlagA.Rotation;
/* Rotation can always use pack settings even
* if childed. Unsual transform scale shouldn't affect rotation. */
writer.WriteQuaternion(t.localRotation, _packing.Rotation);
}
}
/* If there is a teleport pending then apply
* extended flag since thats where teleport resides. */
bool teleport = _teleport;
if (teleport)
changed |= ChangedDelta.Extended;
if (ChangedContains(changed, ChangedDelta.Extended))
{
AutoPackType localPacking = packing.Scale;
flagsA |= UpdateFlagA.Extended;
int startIndexB = writer.Position;
writer.Skip(1);
/* Redundant to do the teleport check here since it was done
* just above, but for code consistency the teleport updateflag
* is set within this conditional with rest of the extended
* data. */
if (teleport)
{
flagsB |= UpdateFlagB.Teleport;
_teleport = false;
}
/* Scale. */
if (_synchronizeScale)
{
//ScaleX
if (ChangedContains(changed, ChangedDelta.ScaleX))
{
original = t.localScale.x;
if (canUpdateData)
dataToUpdate.Scale.x = original;
compressed = original * multiplier;
if (localPacking != AutoPackType.Unpacked && Math.Abs(compressed) <= maxValue)
{
flagsB |= UpdateFlagB.X2;
writer.WriteInt16((short)compressed);
}
else
{
flagsB |= UpdateFlagB.X4;
writer.WriteSingle(original);
}
}
//ScaleY
if (ChangedContains(changed, ChangedDelta.ScaleY))
{
original = t.localScale.y;
if (canUpdateData)
dataToUpdate.Scale.y = original;
compressed = original * multiplier;
if (localPacking != AutoPackType.Unpacked && Math.Abs(compressed) <= maxValue)
{
flagsB |= UpdateFlagB.Y2;
writer.WriteInt16((short)compressed);
}
else
{
flagsB |= UpdateFlagB.Y4;
writer.WriteSingle(original);
}
}
//ScaleZ
if (ChangedContains(changed, ChangedDelta.ScaleZ))
{
original = t.localScale.z;
if (canUpdateData)
dataToUpdate.Scale.z = original;
compressed = original * multiplier;
if (localPacking != AutoPackType.Unpacked && Math.Abs(compressed) <= maxValue)
{
flagsB |= UpdateFlagB.Z2;
writer.WriteInt16((short)compressed);
}
else
{
flagsB |= UpdateFlagB.Z4;
writer.WriteSingle(original);
}
}
}
//Childed.
if (ChangedContains(changed, ChangedDelta.Nested) && ParentBehaviour != null)
{
if (canUpdateData)
dataToUpdate.ParentBehaviour = ParentBehaviour;
flagsB |= UpdateFlagB.Child;
writer.WriteNetworkBehaviour(ParentBehaviour);
}
writer.InsertUInt8Unpacked((byte)flagsB, startIndexB);
}
//Insert flags.
writer.InsertUInt8Unpacked((byte)flagsA, startIndexA);
bool ChangedContains(ChangedDelta whole, ChangedDelta part)
{
return (whole & part) == part;
}
}
Change void SendToClients to this
private void SendToClients()
{
//True if clientAuthoritative and there is an owner.
bool clientAuthoritativeWithOwner = _clientAuthoritative && Owner.IsValid;
//Channel to send rpc on.
Channel channel = Channel.Unreliable;
/* If relaying from client and owner isnt clientHost.
* If owner is clientHost just send current server values. */
if (clientAuthoritativeWithOwner && !Owner.IsLocalClient)
{
/* If there is not new data yet and the last received was not reliable
* then a packet maybe did not arrive when expected. See if we need
* to force a reliable with the last data based on ticks passed since
* last update.*/
if (!_authoritativeClientData.HasData && _authoritativeClientData.Channel != Channel.Reliable && _authoritativeClientData.Writer != null)
{
/* If ticks have passed beyond interpolation then force
* to send reliably. */
uint maxPassedTicks = (uint)(1 + _interpolation + _extrapolation);
uint localTick = _timeManager.LocalTick;
if (localTick - _authoritativeClientData.LocalTick > maxPassedTicks)
_authoritativeClientData.SendReliably();
//Not enough time to send reliably, just don't need update.
else
return;
}
if (_authoritativeClientData.HasData)
{
_changedSinceStart = true;
//Resend data from clients.
ObserversUpdateClientAuthoritativeTransform(_authoritativeClientData.Writer.GetArraySegment(), _authoritativeClientData.Channel);
//Now being sent data can unset.
_authoritativeClientData.HasData = false;
}
}
//Sending server transform state.
else
{
PooledWriter writer = _toClientChangedWriter;
TransformData lastSentData = _lastSentTransformData;
ChangedDelta changed = GetChanged(lastSentData);
//If no change.
if (changed == ChangedDelta.Unset)
{
//No changes since last reliable; transform is up to date.
if (_serverChangedSinceReliable == ChangedDelta.Unset)
return;
_serverChangedSinceReliable = ChangedDelta.Unset;
writer = _toClientChangedWriter;
/* If here then current is unset but last was not.
* Send last as reliable so clients have the latest sent through. */
channel = Channel.Reliable;
}
//There is change.
else
{
//Since this is writing new data, reset the writer.
writer.Clear();
_serverChangedSinceReliable |= changed;
_changedSinceStart = true;
/* If here a send for transform values will occur. Update last values.
* Tick doesn't need to be set for whoever controls transform. */
//Transform t = _cachedTransform;
//lastSentData.Update(0, t.localPosition, t.localRotation, t.localScale, t.localPosition, ParentBehaviour);
lastSentData.Tick = 0;
SerializeChanged(changed, writer, lastSentData);
}
ObserversUpdateClientAuthoritativeTransform(writer.GetArraySegment(), channel);
}
}
Change void SendToServer to this
private void SendToServer(TransformData lastSentTransformData)
{
/* ClientHost does not need to send to the server.
* Ideally this would still occur and the data be ignored
* for statistics tracking but to keep the code more simple
* we won't be doing that. Server out however still is tracked,
* which is generally considered more important data. */
if (IsServerInitialized)
return;
//Not client auth or not owner.
if (!_clientAuthoritative || !IsOwner)
return;
//Channel to send on.
Channel channel = Channel.Unreliable;
//Values changed since last check.
ChangedDelta changed = GetChanged(lastSentTransformData);
//If no change.
if (changed == ChangedDelta.Unset)
{
//No changes since last reliable; transform is up to date.
if (_clientChangedSinceReliable == ChangedDelta.Unset)
return;
//Set changed to all changes over time and unset changes over time.
changed = _clientChangedSinceReliable;
_clientChangedSinceReliable = ChangedDelta.Unset;
channel = Channel.Reliable;
}
//There is change.
else
{
_clientChangedSinceReliable |= changed;
}
/* If here a send for transform values will occur. Update last values.
* Tick doesn't need to be set for whoever controls transform. */
Transform t = _cachedTransform;
//lastSentData.Update(0, t.localPosition, t.localRotation, t.localScale, t.localPosition, ParentBehaviour);
lastSentTransformData.Tick = 0;
//Send latest.
PooledWriter writer = WriterPool.Retrieve();
SerializeChanged(changed, writer, lastSentTransformData);
ServerUpdateTransform(writer.GetArraySegment(), channel);
writer.Store();
}