Skip to content
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 initial synchronization, parenting, smooth transitions between transform spaces, and UI updates #3013

Conversation

NoelStephensUnity
Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity commented Aug 16, 2024

Parenting & Smooth Transform Space Transitions

This PR contains a handful of NetworkTransform fixes pertaining to parenting, the initial synchronizing parented NetworkObjects with newly/late joined clients, issues with smooth transform space transitions (specific to parenting) while interpolation is enabled, and provides the ability to tick synchronize nested and parented NetworkTransform instances.

Side Note: #3039 is the example project to that demonstrates these updates and includes additional (and useful) helper classes.

The below described properties allow for seamless transform space parenting and transitions when interpolation is enabled (primarily focusing on the owner authoritative motion model), and only requires setting the parent of the owned NetworkObject (i.e. no more predicting RTT between the server and client owner) to accomplish this.
Side Note: This is only for non-Rigidbody spawned instances. There will be a follow up PR to handle the Rigidbody approach that will still leverage from some of the below properties, but there is a different dynamic involved with PhysX based "parenting" (i_n reality there is no such thing as local space in the PhysX simulation so using Joints combined with tick synchronized children is the better approach_).

NetworkTransform.SwitchTransformSpaceWhenParented

image
When enabled, the "Tick Sync Children" property is automatically enabled to assure any already parented children will be synchronized properly as well as it handles tick synchronizing nested NetworkTransform components. This also automatically updates owner authoritative's NetworkTransform.InLocalSpace setting, handles updating/converting each LinearBufferInterpolator entries to the proper transform space relative to the current, previous, or current and previous (if doing a NetworkObject to NetworkObject transition) parent(s).

This does not apply to NetworkTransform component(s) paired with NetworkRigidbody component(s), as that will be the next PR update for v2.0.0.

NetworkTransform.TickSyncChildren

When enabled, nested NetworkTransform components will be synchronized with the root NetworkTransform or in the event they are all nested under a root GameObject with NetworkObject component the first NetworkTransform in that hierarchy.

How this works:

When the root NetworkTransform (on the authoritative instance) detects a state update needs to be sent, it will then have all nested and/or child (parented) NetworkTransforms (as long as the client has authority over them) send state updates. This helps to prevent a potential issue where nested or child NetworkTransform components could get into a state where they are all sending updates on different ticks which can lead to visual "jittering" between the associated GameObject transforms.
This property is automatically enabled when NetworkTransform.SwitchTransformSpaceWhenParented is enabled.

NetworkObject.AllowOwnerToParent

image
This is primarily a property for client-server network topology based projects that might use an owner authoritative motion model (typically for player avatars/prefabs). Enabling this property allows the client owner to immediately parent the owned object under another NetworkObject in order to assure there is no latency between the parenting event and NetworkTransform updates. This is especially important when handling NetworkObject to NetworkObject parenting when using a client-server network topology in order to maintain smooth transitions on non-authoritative instances.
Note: Setting this property when using a distributed authority network topology has no effect since client owners already have the authority to handle immediate local parenting.

NetworkObject.SyncOwnerTransformWhenParented

image
When disabled, this property will not apply the server-side transform values received via the ParentSyncMessage on the client owner side. This is more specific to owner authoritative motion models (i.e. NetworkTransform with owner authority) but can be useful under other scenarios where having the client owner not applying the server-side's transform state is required. Disabling this property impacts non-authoritative instances in the following ways (depending upon the network topology being used):

  • Client-server: The non-authoritative instances will always apply the server's transform state. The server's transform state leads the non-authoritative instance(s) state(s) by roughly 1 network tick relative to the client owner's transform state.
  • Distributed authority: The non-authoritative instances will always apply the owner's transform state. Since the client has authority. Because of this, enabling this property has no significant impact.
    When enabled (default), client owner will apply the server's transform state when receiving the ParentSyncMessage from the server (but has no impact when using a distributed authority network topology).

UI Updates & NetcodeEditorBase

This PR also includes a new NetcodeEditorBase editor that can be used with any MonoBehaviour derived component and helps to organize inspector view properties by child class generation. The NetworkTransform, NetworkRigidbodyBase, and NetworkManager editors now derive from NetcodeEditorBase so any child derived from one of these three components will provide this separation of child generation relative properties. When used in their original form (i.e. not a component derived from) it will show only the properties and not apply the foldout group.

Folder Grouping of Each Generational Child

The NetcodeEditorBase, used by NetworkTransform, NetworkRigidbodyBase, and NetworkManager custom editors, provides a clean separation between the base class and any derived child.

NetworkTransform Example:

The NetworkTransform derived both child generation properties are collapsed:
image
Expanding the last generation child, MoverScriptNoRigidbody, properties:
image
Expanding the NetworkTransform parent class properties:
image

NetworkManager Example:

For those who like to store additional netcode and/or project specific settings in the same place, deriving from the NetworkManager while using NetcodeEditorBase for the ExtendedNetworkManagerEditor:
Collapsed:
image
Fully expanded:
image

Multi-Object Compatible

The NetcodeEditorBase is Multi-Object compatible. Below is a prefab with several children selected that have the same PlayerBallMotion : NetworkTransform component:
image
When the NetworkTransform properties are expanded, you get the same custom editor view for all selected objects:
image

MTTB-66
MTTB-6

fix: #2959
fix: #2913
fix: #2856
fix: #2843
fix: #2842

Changelog

  • Added NetworkTransform.SwitchTransformSpaceWhenParented property that, when enabled, will handle the world to local, local to world, and local to local transform space transitions when interpolation is enabled.
  • Added NetworkTransform.TickSyncChildren that, when enabled, will tick synchronize nested and/or child NetworkTransform components to eliminate any potential visual jittering that could occur if the NetworkTransform instances get into a state where their state updates are landing on different network ticks.
  • Added NetworkObject.AllowOwnerToParent property to provide the ability to allow clients to parent owned objects when running in a client-server network topology.
  • Added NetworkObject.SyncOwnerTransformWhenParented property to provide a way to disable applying the server's transform information in the parenting message on the client owner instance which can be useful for owner authoritative motion models.
  • Added NetcodeEditorBase editor helper class to provide easier modification and extension of the SDK's components.
  • Fixed issue with newly/late joined clients and NetworkTransform synchronization of parented NetworkObject instances.
  • Fixed issue with smooth transitions between transform spaces when interpolation is enabled (requires NetworkTransform.SwitchTransformSpaceWhenParented to be enabled).
  • Changed NetworkTransformEditor so it now derives from NetcodeEditorBase.
  • Changed NetworkRigidbodyBaseEditor so it now derives from NetcodeEditorBase.
  • Changed NetworkManagerEditor so it now derives from NetcodeEditorBase.

Testing and Documentation

  • Includes integration tests.
  • Documentation additions are necessary.

This fixes a synchronization issue with owner authoritative instances when running in client-server mode and parenting. When the server sends a parent sync message back with the position of the client's owned object it is out of sync with the client's position by the time the message is received. This fix gives users the option to not synchronize the transform position of a NetworkObject when using an owner authoritative motion mode.
This fix provides users with the option to have child `NetworkTransform`(s) tick synchronized with their parent. When the parent has `TickSyncChildren` enabled, any child `NetworkTransform`(s) that the local client has authority over will force a synchronization of their transform state. When a client is not the authority of the parent but it is the authority of one or more children, then when the parent sends a state update it will force the child/children the client has authority over to send a state update. Children will still send state updates if the transform has a delta that exceeds an axis threshold and the parent has yet to send a synchronization, but if a parent sends a synchronization within the same tick period the child/children will still send another state update.
Better approach, but still flawed.
I think converting any remaining items in the interpolators when the transform space changes will yield consistent results.
Seamless transform space transitions when parenting.
We no longer need to send lossy scale since we defer applying the initial synchronization data until the non-authority side has finished synchronizing.
Fixing some minor issues with nested `NetworkTransforms` (i.e. under the same `NetworkObject`) and adding additional comments.
Reverting back to just checking `InLocalSpace` (as opposed to the interpolator's) when applying a position on the non-authority side.
Fixing some issues with `NestedNetworkTransformTests` assets to account for some past updates.
Fixing an issue with `NetworkTransformTests` where it needs to not just advance the tick (for updates) but needs to also advance to the next tick.
caught scenario where `NetworkObject.NetworkTransforms` could not be set properly.
This fixes a minor "blip" when transitioning from world to local space,
disabling two tests that need to be reviewed by Kitty and/or re-written.
Updating all NetworkTransform instances that belong to a specific NetworkObject as opposed to just the root.
Also not updating when not spawned or disabled NetworkTransforms.
Making test asset adjustments for recent updates in NetworkTransform.
Adding change log entry.
mid-point check-in
Updating interpolation test to recent NetworkTransform updates.
…er-object-parenting-no-sync-transform-option
wip towards getting a cleaner divide between the two modes.
Some adjustments to when nested children check their own state updates or exit early.
Cleaning up some Rigidbody references and making Rigidbody & Rigidbody2D accessible via NetworkRigidbody and NetworkRigidbody2D.
Adding an internal InternalOnNetworkObjectParentChanged method that gets invoked ahead of OnNetworkObjectParentChanged so user code can't override any NGO components that need this kind of notification.
Adding InternalOnNetworkSessionSynchronized to be invoked by NGO components to assure they don't get overridden by user script.
Renaming some internal properties that are common names and would conflict with serialization if a user defined them in a derived class.

Making sure both the position and rotation interpolators are configured for the transform space when reset.

Adding the ability to change the parent locally when running with a client-server network topology.
Adding SwitchTransformSpaceWhenParented property to the NetworkTransformEditor.
Shifting all of the non-authority's final synchronization logic to occur either once a client's initial connection synchronization is complete or when all of the NetworkObject's components have run through the spawn process.
Adding some improved and needed UI updates to NetworkBehaviour derived components and NetworkManager.
This includes a new NetcodeEditorBase class that allows users to more easily create customized, multi-generation, components that have their properties organized based on the generation of each child.
Wrapping the NetworkRigidbodyBaseEditor within physics defines.
>.<

(sigh) null checks can be simplified style/standards update.
NoelStephensUnity added a commit that referenced this pull request Aug 30, 2024
Updating the example to mirror the most recent updates to #3013
@NoelStephensUnity NoelStephensUnity changed the title fix: NetworkTransform initial synchronization, parenting, and smooth transitions between transform spaces fix: NetworkTransform initial synchronization, parenting, smooth transitions between transform spaces, and UI updates Aug 30, 2024
switching from TT as a class to TT as a MonoBehaviour.
This fixes an issue where a server instance parenting with AllowOwnerToParent set would send to itself.
Adding check within the NetworkObject parenting logic to pass through to the server portion of sending the parenting message.
adding some validation tests for the updates made in #3013
adding changelog entries
@NoelStephensUnity NoelStephensUnity marked this pull request as ready for review August 30, 2024 17:59
@NoelStephensUnity NoelStephensUnity requested a review from a team as a code owner August 30, 2024 17:59
This fixes the two failing tests within NetworkTransformAnticipationTest and updates AnticipatedNetworkTransform to account for #3013's updates/changes.
Removing the added base.OnInspectorGUI() call (was causing duplicated properties)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a little comment here. I like the foldout idea, but I think maybe we can take the call-to-action buttons out so users can access them without expanding the foldout content, especially during runtime when there's nothing much within the foldout section. I made a quick mock here! Please lemme know if this makes sense!

Side note: would it make sense to show network manager properties during runtime? will people need this information?

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome feedback... and good points.
Made the suggested changes and pushed the update.
👍

Assure the callouts and call-to-action buttons show up outside of the Foldout Group when extending NetworkManager.
Assure that the NetworkManager has no Foldout Group when it is not extended.
@NoelStephensUnity NoelStephensUnity merged commit aee018c into develop-2.0.0 Sep 5, 2024
23 checks passed
@NoelStephensUnity NoelStephensUnity deleted the fix/owner-object-parenting-no-sync-transform-option branch September 5, 2024 15:12
NoelStephensUnity added a commit that referenced this pull request Sep 9, 2024
…th parenting transform space transitions (#3039)

* chore

Adding example of using a CharacterController that has no Rigidbody and being able to parent it under a moving and/or rotating body.
This uses to be finalized NetworkTransform updates for NGO v2.x.x.

* chore

adding the manifest file

* chore

removing packages file

* update

Adding gitignore

* fix

Adding an elevator moving body.
Fixing issue with disabling the GameObject vs disabling the CharacterController.

* update

Updating the example to mirror the most recent updates to #3013

* Create Readme.md

place holder read me

* Update Readme.md

WIP updates added some additional sections and screenshots

* update

Adding [CanEditMultipleObjects] to RotatingBodyLogicEditor.
Minor scene updates.

* Update Readme.md

* Update Readme.md

* update

cleaning up a bit.
combining connect disconnect notifications into the extended networkmanager.
made the single z-axis motion a path as opposed to the hacky way I did it originally.

* update

Adding some bumpers for extended networkmanager and selecting a connection type vs the selected network topology and vice versa.

* Update Readme.md

* update

pointing to the develop-2.0.0 branch
@NoelStephensUnity NoelStephensUnity added the type:backport-release-1.0.0 This PR should be backported to 1.0.0 label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:backport-release-1.0.0 This PR should be backported to 1.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants