com.unity.netcode.gameobjects
com.unity.netcode.gameobjects copied to clipboard
NetworkTransform 1.11.0 can initialize world space objects to wrong position
NetworkTransform in Netcode 1.11.0 (Unity 2022.3.10f1) can move objects with world space sync configuration to the incorrect location. This was initially reported as #2913, but I have now identified the full repro case and cause, and it was not fixed via #2888.
I have a good trace of the problem where it seems the host is never sending a NetworkTransformMessage, or I have not been able to identify where the remote client is ignoring the message.
The gist of the issue is that all objects begin their life with local space position updates and then NetworkTransform sends a single NetworkTransformMessage with a NetworkTransformState that changes InLocalSpace to False while also HasPositionChange is True and a new PositionX/Y/Z is provided. Subsequent messages also have InLocalSpace be False but there may be no position changes. I am seeing -- often, but intermittently -- the first and most important message never arrive or never get processed by clients. This results in that object with the NetworkTransform having its NetworkObject initialization local space coordinates be applied as world coordinates, and so the object is moved to the wrong location.
Repro
I have a large gameplay scene that is additively loaded. It has over 300 NetworkObjects and over 50 NetworkTransforms.
There is one type of object that ends up being moved by the NetworkTransform to the incorrect location. (The bug is intermittent, and it feels like a CPU race condition rather than a latency-based network race condition?) I can repro the bug in local two-Editor testing with ParrelSync and also in builds when connecting to a remote client over WAN. The bug seemed slightly more common in the build scenario.
Here is an example Hiearchy for this type of object:
0,0,0(NetworkObject)0,0,00,0,00,-3,036.648571,-2.14999914,-39.39714430,0,0-14.4399996,0.150002956,-10.0100002(NetworkObject,NetworkTransform) name = Monster
Monster is an in-scene placed NetworkObject prefab with a NetworkTransform. It has no Rigidbody. It is active in the scene. It has a bunch of non-NetworkObject parents -- some of them are not at 0,0,0 -- and then one parent at the root level that is a NetworkObject.
Root NetworkObject settings are:
Always Replicate = True
Sync Transform = True
Active Scene Sync = False
Scene Migration Sync = True
Spawn With Observ = True
Dont Destroy = False
Auto Object Parent Sync = False or True... tested both, doesn't matter`
Monster NetworkObject settings are:
Always Replicate = False
Sync Transform = True
Active Scene Sync = False
Scene Migration Sync = True
Spawn With Observ = True
Dont Destroy = False
Auto Object Parent Sync = True
Monster NetworkTransform settings are:
yes to sync all of the Transform parts
default Thresholds
Use Unreliable Deltas = False
In Local Space = False
Interpolate = True
Slerp = False
Use Quat Sync = False
Use Half Float = False
Trace
When it doesn't happen:
When it does happen:
Changed Netcode 1.11.0 files
These changes were used to generate the gratuitous logging above. Also noteworthy is some of the gratuitous logging that did not show up in the logs as well... which is what indicates to me that the NetworkTransformMessage is never even received by the remote client when the bug happens.
@zachstronaut After re-reading this issue, I am thinking that #3388 could resolve your issue. Could you try out the develop branch with your project and see if your issue no longer exists?
@NoelStephensUnity one case it appears to not fix is when you are spawning an object, changing the ownership of the object, and then re-parenting the object all in one go. If you do all that, there is still bad position data that gets serialized and sent over in the NetworkTransform and things end up getting moved somewhere they don't belong.
@NoelStephensUnity one case it appears to not fix is when you are spawning an object, changing the ownership of the object, and then re-parenting the object all in one go. If you do all that, there is still bad position data that gets serialized and sent over in the NetworkTransform and things end up getting moved somewhere they don't belong.
This could be fixed with the ParentSyncMessage back-port I believe.
This issue has been automatically marked as stale because it has been awaiting response for over 30 days without any activity. Please update the issue with any new information or it may be closed in 30 days.
This issue has been automatically closed because it has been stale for 30 days without any activity. Feel free to reopen if you have new information to add.