-
Notifications
You must be signed in to change notification settings - Fork 457
fix: Parenting does not preserve WorldPositionStays option and other parenting related issues #2146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
611aed6
e0164c4
9f5d7ec
15fa292
413e5ff
05a2e92
e7b1ec6
9a92f3a
f2ad223
2e9b2bb
02b281e
4eb3665
1b6656e
84b18b5
9fa5e0b
80d1af5
c798c47
3704e84
d24443b
eca807d
1250f30
8d18c1d
80de0e9
1ef4c63
babd4a2
d478169
ae8fade
5016303
2e43737
95ae7bb
c735a38
2d98f75
76c0e85
d7384b4
e767757
505b27b
0408358
839ff2e
0b7b3ae
8ea66a8
2488249
19a291d
0532a4f
7817eb1
02de172
1e19f30
98318cf
fdbad87
0a1558f
b2e4516
a7b1e72
aab4980
aecb750
46eb1ef
0a74e63
1a87cdb
c659916
4a60e1b
0a3f0d8
1972488
289bf72
a51ae69
719ffa2
1ab8128
30ba251
0adc908
b9fb55b
45e8c8d
da1372b
682c020
058f401
dc54216
89a50a4
7e5bcd3
c13b3f2
59cf57a
e6d654c
4db2627
9ab7199
956d331
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -451,19 +451,6 @@ internal NetworkTransformState GetLastSentState() | |
return m_LastSentState; | ||
} | ||
|
||
/// <summary> | ||
/// Calculated when spawned, this is used to offset a newly received non-authority side state by 1 tick duration | ||
/// in order to end the extrapolation for that state's values. | ||
/// </summary> | ||
/// <remarks> | ||
/// Example: | ||
/// NetworkState-A is received, processed, and measurements added | ||
/// NetworkState-A is duplicated (NetworkState-A-Post) and its sent time is offset by the tick frequency | ||
/// One tick later, NetworkState-A-Post is applied to end that delta's extrapolation. | ||
/// <see cref="OnNetworkStateChanged"/> to see how NetworkState-A-Post doesn't get excluded/missed | ||
/// </remarks> | ||
private double m_TickFrequency; | ||
|
||
/// <summary> | ||
/// This will try to send/commit the current transform delta states (if any) | ||
/// </summary> | ||
|
@@ -488,14 +475,16 @@ protected void TryCommitTransformToServer(Transform transformToCommit, double di | |
} | ||
else // Non-Authority | ||
{ | ||
var position = InLocalSpace ? transformToCommit.localPosition : transformToCommit.position; | ||
var rotation = InLocalSpace ? transformToCommit.localRotation : transformToCommit.rotation; | ||
// We are an owner requesting to update our state | ||
if (!m_CachedIsServer) | ||
{ | ||
SetStateServerRpc(transformToCommit.position, transformToCommit.rotation, transformToCommit.localScale, false); | ||
SetStateServerRpc(position, rotation, transformToCommit.localScale, false); | ||
} | ||
else // Server is always authoritative (including owner authoritative) | ||
{ | ||
SetStateClientRpc(transformToCommit.position, transformToCommit.rotation, transformToCommit.localScale, false); | ||
SetStateClientRpc(position, rotation, transformToCommit.localScale, false); | ||
} | ||
} | ||
} | ||
|
@@ -521,37 +510,24 @@ private void TryCommitTransform(Transform transformToCommit, double dirtyTime) | |
} | ||
} | ||
|
||
/// <summary> | ||
/// Initializes the interpolators with the current transform values | ||
/// </summary> | ||
private void ResetInterpolatedStateToCurrentAuthoritativeState() | ||
{ | ||
var serverTime = NetworkManager.ServerTime.Time; | ||
|
||
// TODO: Look into a better way to communicate the entire state for late joining clients. | ||
// Since the replicated network state will just be the most recent deltas and not the entire state. | ||
//m_PositionXInterpolator.ResetTo(m_LocalAuthoritativeNetworkState.PositionX, serverTime); | ||
//m_PositionYInterpolator.ResetTo(m_LocalAuthoritativeNetworkState.PositionY, serverTime); | ||
//m_PositionZInterpolator.ResetTo(m_LocalAuthoritativeNetworkState.PositionZ, serverTime); | ||
|
||
//m_RotationInterpolator.ResetTo(Quaternion.Euler(m_LocalAuthoritativeNetworkState.RotAngleX, m_LocalAuthoritativeNetworkState.RotAngleY, m_LocalAuthoritativeNetworkState.RotAngleZ), serverTime); | ||
|
||
//m_ScaleXInterpolator.ResetTo(m_LocalAuthoritativeNetworkState.ScaleX, serverTime); | ||
//m_ScaleYInterpolator.ResetTo(m_LocalAuthoritativeNetworkState.ScaleY, serverTime); | ||
//m_ScaleZInterpolator.ResetTo(m_LocalAuthoritativeNetworkState.ScaleZ, serverTime); | ||
|
||
// NOTE ABOUT THIS CHANGE: | ||
// !!! This will exclude any scale changes because we currently do not spawn network objects with scale !!! | ||
// Regarding Scale: It will be the same scale as the default scale for the object being spawned. | ||
var position = InLocalSpace ? transform.localPosition : transform.position; | ||
m_PositionXInterpolator.ResetTo(position.x, serverTime); | ||
m_PositionYInterpolator.ResetTo(position.y, serverTime); | ||
m_PositionZInterpolator.ResetTo(position.z, serverTime); | ||
|
||
var rotation = InLocalSpace ? transform.localRotation : transform.rotation; | ||
m_RotationInterpolator.ResetTo(rotation, serverTime); | ||
|
||
// TODO: (Create Jira Ticket) Synchronize local scale during NetworkObject synchronization | ||
// (We will probably want to byte pack TransformData to offset the 3 float addition) | ||
m_ScaleXInterpolator.ResetTo(transform.localScale.x, serverTime); | ||
m_ScaleYInterpolator.ResetTo(transform.localScale.y, serverTime); | ||
m_ScaleZInterpolator.ResetTo(transform.localScale.z, serverTime); | ||
var scale = transform.localScale; | ||
m_ScaleXInterpolator.ResetTo(scale.x, serverTime); | ||
m_ScaleYInterpolator.ResetTo(scale.y, serverTime); | ||
m_ScaleZInterpolator.ResetTo(scale.z, serverTime); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -602,63 +578,63 @@ private bool ApplyTransformToNetworkStateWithInfo(ref NetworkTransformState netw | |
isDirty = true; | ||
} | ||
|
||
if (SyncPositionX && Mathf.Abs(networkState.PositionX - position.x) >= PositionThreshold || networkState.IsTeleportingNextFrame) | ||
if (SyncPositionX && (Mathf.Abs(networkState.PositionX - position.x) >= PositionThreshold || networkState.IsTeleportingNextFrame)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This bug I found while debugging parent-child scale issues when the NetworkObject also had a NetworkTransform. I had turned the NetworkTransform scale synchronization flags (X, Y,Z) off but it seemed to keep updating them...which made me realize the initial state after 1 or 2 network ticks is a "teleport state"...which the previous logic (without the braces) would apply all axis whether marked to be synchronized or not. |
||
{ | ||
networkState.PositionX = position.x; | ||
networkState.HasPositionX = true; | ||
isPositionDirty = true; | ||
} | ||
|
||
if (SyncPositionY && Mathf.Abs(networkState.PositionY - position.y) >= PositionThreshold || networkState.IsTeleportingNextFrame) | ||
if (SyncPositionY && (Mathf.Abs(networkState.PositionY - position.y) >= PositionThreshold || networkState.IsTeleportingNextFrame)) | ||
{ | ||
networkState.PositionY = position.y; | ||
networkState.HasPositionY = true; | ||
isPositionDirty = true; | ||
} | ||
|
||
if (SyncPositionZ && Mathf.Abs(networkState.PositionZ - position.z) >= PositionThreshold || networkState.IsTeleportingNextFrame) | ||
if (SyncPositionZ && (Mathf.Abs(networkState.PositionZ - position.z) >= PositionThreshold || networkState.IsTeleportingNextFrame)) | ||
{ | ||
networkState.PositionZ = position.z; | ||
networkState.HasPositionZ = true; | ||
isPositionDirty = true; | ||
} | ||
|
||
if (SyncRotAngleX && Mathf.Abs(Mathf.DeltaAngle(networkState.RotAngleX, rotAngles.x)) >= RotAngleThreshold || networkState.IsTeleportingNextFrame) | ||
if (SyncRotAngleX && (Mathf.Abs(Mathf.DeltaAngle(networkState.RotAngleX, rotAngles.x)) >= RotAngleThreshold || networkState.IsTeleportingNextFrame)) | ||
{ | ||
networkState.RotAngleX = rotAngles.x; | ||
networkState.HasRotAngleX = true; | ||
isRotationDirty = true; | ||
} | ||
|
||
if (SyncRotAngleY && Mathf.Abs(Mathf.DeltaAngle(networkState.RotAngleY, rotAngles.y)) >= RotAngleThreshold || networkState.IsTeleportingNextFrame) | ||
if (SyncRotAngleY && (Mathf.Abs(Mathf.DeltaAngle(networkState.RotAngleY, rotAngles.y)) >= RotAngleThreshold || networkState.IsTeleportingNextFrame)) | ||
{ | ||
networkState.RotAngleY = rotAngles.y; | ||
networkState.HasRotAngleY = true; | ||
isRotationDirty = true; | ||
} | ||
|
||
if (SyncRotAngleZ && Mathf.Abs(Mathf.DeltaAngle(networkState.RotAngleZ, rotAngles.z)) >= RotAngleThreshold || networkState.IsTeleportingNextFrame) | ||
if (SyncRotAngleZ && (Mathf.Abs(Mathf.DeltaAngle(networkState.RotAngleZ, rotAngles.z)) >= RotAngleThreshold || networkState.IsTeleportingNextFrame)) | ||
{ | ||
networkState.RotAngleZ = rotAngles.z; | ||
networkState.HasRotAngleZ = true; | ||
isRotationDirty = true; | ||
} | ||
|
||
if (SyncScaleX && Mathf.Abs(networkState.ScaleX - scale.x) >= ScaleThreshold || networkState.IsTeleportingNextFrame) | ||
if (SyncScaleX && (Mathf.Abs(networkState.ScaleX - scale.x) >= ScaleThreshold || networkState.IsTeleportingNextFrame)) | ||
{ | ||
networkState.ScaleX = scale.x; | ||
networkState.HasScaleX = true; | ||
isScaleDirty = true; | ||
} | ||
|
||
if (SyncScaleY && Mathf.Abs(networkState.ScaleY - scale.y) >= ScaleThreshold || networkState.IsTeleportingNextFrame) | ||
if (SyncScaleY && (Mathf.Abs(networkState.ScaleY - scale.y) >= ScaleThreshold || networkState.IsTeleportingNextFrame)) | ||
{ | ||
networkState.ScaleY = scale.y; | ||
networkState.HasScaleY = true; | ||
isScaleDirty = true; | ||
} | ||
|
||
if (SyncScaleZ && Mathf.Abs(networkState.ScaleZ - scale.z) >= ScaleThreshold || networkState.IsTeleportingNextFrame) | ||
if (SyncScaleZ && (Mathf.Abs(networkState.ScaleZ - scale.z) >= ScaleThreshold || networkState.IsTeleportingNextFrame)) | ||
{ | ||
networkState.ScaleZ = scale.z; | ||
networkState.HasScaleZ = true; | ||
|
@@ -1007,7 +983,6 @@ public override void OnNetworkSpawn() | |
{ | ||
m_CachedIsServer = IsServer; | ||
m_CachedNetworkManager = NetworkManager; | ||
m_TickFrequency = 1.0 / NetworkManager.NetworkConfig.TickRate; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 nice unused variable |
||
|
||
Initialize(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed this while working on parenting with multi-generation nested children (there was a bug elsewhere it turned out). I went ahead and fixed it as I have more parenting integration tests I am working on that will be using this method when the parented NetworkObjects have a NetworkTransform too.