-
Notifications
You must be signed in to change notification settings - Fork 437
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
fix: NetworkTransform Mixed Unreliable & Reliable Order of Operations #2777
fix: NetworkTransform Mixed Unreliable & Reliable Order of Operations #2777
Conversation
Deferring anything that occurs on the same tick after we already sent a delta state update, exiting early if we had already sent a deferred state on the same tick, and not attempting to forward a state update message if there are no additional remote clients to forward it to. Adding a single tick wait at the start of the change one at a time test as it seemed to be running too fast where time had yet to be synchronized proir to setting state.
Hey @NoelStephensUnity. I've noticed this merge request because I have a similar problem. I tried this branch and unfortunately it didn't resolve my problem, although I'm not sure it 's order of operation problem. My character has [ClientRpc]
void SomeClientRpc(Vector3 moveTo, ClientRpcParams rpcParams = default) {
var character = NetworkManager.LocalClient.PlayerObject.transform;
character.position = new Vector3(moveTo.x, character.transform.position.y, moveTo.z);
character.LookAt(new Vector3(transform.position.x, character.position.y, transform.position.z));
character.GetComponent<Rigidbody>().position = character.position; // just tried this way too
character.GetComponent<Rigidbody>().rotation = character.rotation;
} This code is from another This is what I have in my "com.unity.netcode.gameobjects": "https://github.com/Unity-Technologies/com.unity.netcode.gameobjects.git?path=com.unity.netcode.gameobjects#500f2be18805a16fead8ba9bcb96d8c333ca739f", I'm not sure it's related to this PR, but still... teleport_bug.webm |
I would highly recommend taking a look at issue #2765 as there can be an order of operations issue involved when dealing with physics bodies and applying values immediately upon an inbound message being received and processed. I have also opened up a documentation PR to provide more details about inbound message processing, order of operation, and physics so this information is more readily available. The common symptom (as described in my explanation in #2765) is that when you apply your changes on the authoritative side it "seems to work just fine" but then when you have a remote client signal to apply changes (i.e. via ServerRpc) it can sometimes be inconsistent (or not work at all). With your scenario it would seem that it is similar to the #2765 scenario but just inverted where the host-server is driving the teleport/move-to event and your authoritative side (owner/client authoritative) is applying the results of the event during the EarlyUpdate (when inbound messages are processed) prior to the FixedUpdate. The solution is to not apply the changes immediately when the ClientRpc is received, but to defer the changes to a later update stage (i.e.
This should avoid the issue you are seeing on the client side and if you do want it to "truly teleport" then using SetState will make sure that it looks visually correct on the non-authoritative instances. This PR was originally put together because of how unreliable and reliable messages do not have any guarantee in the order they are received and processed (relative to each other and not to messages of the same delivery type). This led me to discover an explicit state update (i.e. SetState) could be invoked after an implicit delta state update (i.e. normal tick update) had already been sent on the same frame. In order to preserve the explicit state update, this PR defers the explicit state update the next frame. |
Removing a teleport check that didn't need to be there. Updating comments for clarity and grammar/spelling.
Yes, it worked in my case, thanks! |
…orderofoperations
…orderofoperations
This update fixes several issues with tests and with the initial unreliable delta state update changes. When explicitly setting state, it now is additive regarding flag states (i.e. it does not send outside of the tick event generated window). Condensed the packet loss and standard network transform commonly shared code into a single NetworkTransformBase class. Since state is not immediately pushed, had to update NestedNetworkTransforms test. Updated several test projects that still had references to the UNet component which no longer exists in 2021.
…orderofoperations
Fixing some issues with the TestRotationThresholdDeltaCheck test. Updated NetcodeIntegrationTest to provide a generic test relative TimeTravelAdvanceTick to assure all tests are operating at their set frame rate and tick values. Added TestMultipleExplicitSetStates test to validate explicitly setting state multiple times within the same fractional tick period will be preserved and propogate out on the next upcoming tick.
When sending unreliable delta state updates, it is possible for the following sequence of events to happen:
Where the teleport state update that should proceed the deltas state update ends up preceding it which can cause a temporary out-of-synch issue if interpolation is disabled but can cause a relatively noticeable "visual anomaly" if interpolation is enabled the the original position is a reasonable distance from the teleported position.
In this update:
NetworkTransform
was adjusted to assure explicitly set states are not sent during a fractional tick period.NetworkTransform
related tests:NetworkTransformPacketLossTests
andNetworkTransformTests
within a new base class:NetworkTransformBase
.NetworkTransformTests
that were running on all test fixture iterations (and did not need to be) and migrated them to a newNetworkTransformGeneral
set of tests.NetcodeIntegrationTest
:GetFrameRate
: virtual method used inConfigureFramesPerTick
calculations.GetTickRate
: virtual method used inConfigureFramesPerTick
calculations.ConfigureFramesPerTick
: This calculates the number of frames within a single tick period and the tick frequencyTimeTravelAdvanceTick
: time travels for the duration of the tick frequency or the number of frames within a tick period has passed.MTT-7775
Changelog
NetworkTransform
was using theNetworkManager.ServerTime.Tick
as opposed toNetworkManager.NetworkTickSystem.ServerTime.Tick
during the authoritative side's tick update where it performed a delta state check.NetworkTransform.SetState
(and related methods) now are cumulative during a fractional tick period and sent on the next pending tick.Testing and Documentation
NetworkTransformPacketLossTests.TestSameFrameDeltaStateAndTeleport
NetworkTransformGeneral.TestMultipleExplicitSetStates