Граф коммитов

97 Коммитов

Автор SHA1 Сообщение Дата
Noel Stephens 490fb939a5
fix: networkanimator only updates observers backport (#3058)
* fix

only send animation updates to observers.

* test

validates that NetworkAnimator only sends animation updates to observers.

* update

Added changelog entry
2024-09-11 09:40:28 -04:00
Noel Stephens b2f5e84591
fix: dual triggers generating false state transition [MTTB-48] (#2999)
* fix

This fixes the issue where a trigger that transitions to a state with a trigger that transitions back to the original state could cause NetworkAnimator to generate a false layer to layer state transition which would not only generate an additional message after the original trigger message, but would cause the non-authority instances to log a warning message.

* test - manual

This includes additional assets needed to test this fix manually as well as some of the assets included will be used in an integration test.

* test

Adding test for the dual trigger scenario.

* style

Adding additional comments about the update.
2024-08-07 02:38:39 +00:00
Noel Stephens 2b38d55d2d
fix: unreliable deltas half float synch jitter (#2922)
* fix

This fixes an issue with using unreliable state updates, half-floats, and NetworkDeltaPosition.

* test

Adding test to validate the fix for using half float precision with unreliable deltas.
2024-05-14 08:28:44 -05:00
Noel Stephens f9c67313b4
fix: in-scene networkobject with networktransform synchronization when parented under gameobject [MTT-8402] (#2895)
* fix

Fixing issue where parenting synchronization on the authority side was not properly handling the scenario where a NetworkObject is parented under a GameObject (with or without auto object parent sync enabled).

* fix

Fixing issue where parenting synchronization on the non-authority side was not properly handling the scenario where a NetworkObject is parented under a GameObject (with or without auto object parent sync enabled).

* update

migrate when to apply in local space above the parenting check.

* test

Adding an integration test to validate an in-scene placed NetworkObject's initial synchronization when parented under a GameObject. This also test both scenarios where the in-scene placed NetworkObject does and does not have a NetworkTransform.

* style

Removing unused namespace

* update

Updating change log entry
2024-05-10 16:00:51 +01:00
Noel Stephens bcb891b5b2
fix: NetworkRigidbody2D not changing body type with authority [MTT-8510] (#2916)
* fix

This resolves the issue with Rigidbody2d not changing the body type based on changes to authority while also assuring the initial body type for Rigidbody2d is kinematic until spawned.

* test

Realized we needed an overhaul with our rigid body tests so I did a bit of refactoring.
Deleted the remaining of the completely commented out rigid body tests that are now being covered in the NetworkRigidbodyTests.
2024-05-09 09:46:12 -05:00
Noel Stephens 3ca359d05f
chore: migrate PR-2812 remove animator requirement (#2872)
* Do not require component Animator on NetworkAnimator.

* update

Adding changelog entry.

---------

Co-authored-by: jeffgamedev <jbrooks@gala.games>
Co-authored-by: Jeff Brooks <jeph.brooks@gmail.com>
2024-04-05 17:58:23 +00:00
Noel Stephens ac46fa7fda
fix: NetworkTransform synchronize position when half float precision is enabled (#2845)
* fix

Edge case fix for half float precision not getting the proper initial base offset.

* update

adding change log entry

* update

adding PR number

* test

updating some of the tests to reduce the verbosity of the debug output.
2024-04-05 16:09:59 +00:00
Kitty Draper b9fe0d2048
feat: Added support for client anticipation in NetworkVariables and NetworkTransform and support for throttling functionality in NetworkVariables (#2820) 2024-03-27 19:19:56 +00:00
Nicklas Pingel 7a2f31a696
fix: Freeze rigidbody on Awake and interpolate based on ownership (#2838)
NetworkRigidbody is not checking for NetworkTransform.Interpolate value on ownership loss as it does on Awake, so it assumes that the NetworkTransform will treat the interpolation even if NetworkTransform.Interpolate is false.

NetworkRigibody set kinematic on a NetworkObject's rigidbody before it actually is spawned (on Awake) to prevent the transform from being changed before knowing the actual ownership of the object. NetworkRigidbody2D follow the same pattern
2024-03-11 09:37:04 -05:00
Noel Stephens adcec184ac
chore: migrate NetworkTransform away from using named messages over to NetworkTransformMessage [MTT-7535] (#2810)
* update
Adding the NetworkTransformMessage
Expanding INetworkMessgeILPP assembly processing to Unity.Netcode.Components.
2024-01-17 09:55:58 +00:00
Noel Stephens 64ed674c64
fix: handle null or empty named message registration [MTT-7771] (#2807)
* fix

Fixes issue where registering or unregistering named message that is null or empty does not throw an exception.
Fixes issue where it was possible that NetworkTransform could try to unregister a named message before it had been assigned a value.

* update

Actually decided to make both cases log an error and raised the minimum loglevel.

* test

Adding a test to verify that trying to register or unregister a null or empty named message will not throw an exception.

* style

removing whitespace

* update

Adding change log entries
2024-01-13 01:58:30 +00:00
Noel Stephens 53b735c70f
fix: NetworkTransform half float synch (#2791)
* fix

Fixing the issue with HalfFloat position not keeping the base position synchronized when using unreliable deltas.
2023-12-13 20:31:27 +00:00
Noel Stephens 654e4134f7
fix: shutdown and shutdown notification issues [MTT-7791] [MTT-7540] (#2789)
* fix

Just return from OnClientDisconnectFromServer when the server is shutting down as there is no point in doing ownership cleanup or client disconnected notification messages at that point.

* Fix

Approaching this fix a different way since we still should send out client disconnect notifications and such.

* fix

Server or host was not sending disconnect when it shutdown.

* update

When a client disconnects itself or is disconnected by the server, it now returns its client identifier.

Server or host shutdown sequence now includes a "soft shutdown" where the server-host will send out disconnection messages to all clients with the reason for the client being disconnected.

* update

the test project exit button script is now a bit more intelligent with how it handles exiting and now logs the reason for disconnection.

* fix - testproject

fixing exceptions when certain missing properties are not set (primarily buttons or toggles)

* test

updating tests for changes.

* fix

Don't allow a host or server to disconnect its local client.

* update

Adding changelog entries

* style

removing unused namespace.

* fix

Fixes issue with NetworkVariable and NetworkList throwing exceptions upon shutdown.

* Test

Validates that setting NetworkVariables or NetworkList values during OnNetworkDespawn does not throw an exception.

* update

adding change log entry

* style

fixing warning message about setting network variable/list values during a shutdown.

* test

Removing unrequired null check

* style

remove the cr/lf after some else if statments

* Minor formatting changes.

* update

Adjusting warning message language.
Adjusting when the send queue is processed.

* update

reverting back moving the MessageManager?.ProcessSendQueues(); within Shutdown and removing the migration of that out of OnClientDisconnectFromServer.

---------

Co-authored-by: Kitty Draper <kitty.draper@unity3d.com>
2023-12-11 09:11:27 -06:00
Noel Stephens 13d1f8c424
fix: NetworkTransform Mixed Unreliable & Reliable Order of Operations (#2777)
* fix

- This resolves an issue with mixing reliable and unreliable messages that could impact teleporting if a state delta was sent prior to teleporting on the same NetworkTick within the same frame.
- The staggered tick for axis sync was not including the current server tick as part of its initial value causing a frame synch every other tick.
-  Ignoring any new state update that has a tick value lower than the last/old state update when using unreliable deltas.

* update

- increasing time out period
- Did some clean up and fixed some issues with the one at a time NetworkTransformTest.
- Renamed m_SetNetworkTransformState to TeleportingNetworkTransformState and made it internal for testing purposes.
- When explicitly setting state, it now is cumulative regarding flag states (i.e. it does not send outside of the tick event generated window).
- Making explicitly set states persist the exact state at the time it was set in order to assure no additional transform modifications are updated implicitly.
- Updated several test projects that still had references to the UNet component which no longer exists in 2021.
- Switching from ReliableFragmentedSequenced to ReliableSequenced.

* test

- Cleaned up the packet loss test and running it at the default tick rate.
- Added a test to validate that when teleporting on the same tick  and frame that an unreliable delta state update was sent that the teleport state update is deferred to the next tick.
- Includes several fixes for issues with NetworkTransform tests and with the initial unreliable delta state update changes.
- Condensed the packet loss and standard network transform commonly shared code into a single NetworkTransformBase class.
- 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.
- Fixed 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.
- Excluding the packet loss test for UTP v2.x.
2023-12-05 04:03:55 +00:00
Noel Stephens d099d647ba
fix: NetworkTransform dropped packets can cause interpolation stutter [MTT-7551] (#2713)
* update

Adding OnOwnershipChanged(ulong previous, ulong current)

* fix

This resolves the issue with client authoritative network transforms and the random "noise" that would occur when transitioning ownership from a remote client back to the host-server.
- Latent messages from the client would still be received and processed after ownership changed.
- Ownership changed messages would proceed the NetworkTransform initialization state update message. Now ownership changed messages precede the NetworkTransform initialization state update message.
- Clients could sometimes have the same network tick value even when the tick event had triggered, which for NetworkDeltaPosition would cause dropped state updates.

* test

minor adjustment to a test that would fail from time to time due to precision.

* Merge branch 'develop' into fix/networktransform-halffloat-ownership-sync

* fix - validation bug

This is another bug in the validation test suite where removing an override of a virtual method that can still be overridden will throw an API validation error.

* update

Send deltas unreliable but synchronization and teleporting reliably.

* style

white space fixes

* test

Fixing issue with changes that require a NetworkManager to be present.

* fix

Fixing new issues (due to changes) with position not synchronizing to the target position when half float precision was enabled.

* test

minor adjustments to account for minor precision delta when quaternion compression is enabled in the NetworkTransformTests.ParentedNetworkTransformTest

* update

Resolves the api validation issue.

* update

Updating rotation and scale delta checks when sending unreliable messages.

* update

Was doing some profiling and found a few low hanging fruit areas that helps improve performance.

* style

removing whitespace

* fix

More adjustments to handle sending unreliable deltas. These changes will (when sending unreliable deltas):
- Stagger NetworkTransform axial frame synchronization
  - Axial frame synchronization is sent reliably
  - Axial frame synchronization is sent only if deltas have been sent (once to assure when an object stops it no longer sends syncs)

This also adjusts the "one tick event updates all NetworkTransform authority instances" addition.

* test

Fixing an issue with precision adjustments for rotation.
Adding integration test to validate the handling of dropped packets.

* update and style

Removing unused namespace.
Removing reference to static variable that no longer exists (was for debugging)

* style

removed whitespaces

* test

Removing UseUnreliableDeltas when running the TestRotationThresholdDeltaCheck as the synchronization frame could cause this test to fail.

* fix

Noticed a potential timing related parenting issue where a parented object should be fully synchronized by  NetworkTransform (even though it sends transform information when parenting).

* test

Some additional tweaks to the parenting portion of the NetworkTransform tests.

* revert

Reverting the parenting adjustment, that was a bad idea.
Only reset and update interpolators if interpolation is enabled seems to resolve the earlier issue.

* test

removing unused methods.
adding 100ms latency to the NetworkTransformUTPTests.

* test

Renaming NetworkTransformUTPTests to NetworkTransformPacketLossTests

* update

Exposing the UseUnreliableDeltas property and adding UI/UX to provide users a way to disable this via the inspector view.

* test

Making NetworkTransformTests run with UseUnreliableDeltas disabled to validate this operation mode of NetworkTransform.

* test

Adding additional wait for added latency.

* update

adding change log entries.

* update

Removing some todo statements and finalizing a bit flag to assure non-authoritative instances mirror the authoritative instance's UseUnreliableDeltas settings (i.e. if owner authoritative and ownership changes the same settings should apply).

* update

Updating change log entry

* Update CHANGELOG.md

Fixing bad changelog merge

* Update CHANGELOG.md

adding CR/LF

* fix

Discovered a long time standing parenting issue with the initial synchronization (while working on something else). The issue involves WorldPositionStays, InLocalSpace,  and the initial synchronization. Added comments to describe the adjustments.
Basically, when synchronizing, ignore the InLocalSpace setting and only use the WorldPositionStays value to determine which position space to use on the authoritative side only when building the initial synchronization state update.

* Update NetworkTransformStateTests.cs

Just adjusting the way a test asserts on null based on suggested review feedback.

* update

minor adjustments to when we need to send a reliable packet when sending unreliable deltas.
2023-11-13 18:14:36 -06:00
Noel Stephens aa7ecbfb5e
fix: ClientNetworkTransform ownership change with half precision synchronization issues [MTT-7271] (#2712)
* update

Adding OnOwnershipChanged(ulong previous, ulong current)

* fix

This resolves the issue with client authoritative network transforms and the random "noise" that would occur when transitioning ownership from a remote client back to the host-server.
- Latent messages from the client would still be received and processed after ownership changed.
- Ownership changed messages would proceed the NetworkTransform initialization state update message. Now ownership changed messages precede the NetworkTransform initialization state update message.
- Clients could sometimes have the same network tick value even when the tick event had triggered, which for NetworkDeltaPosition would cause dropped state updates.
2023-10-03 11:25:00 -05:00
Noel Stephens b5b8edae4a
fix: client not tracking changes to layer weights [MTT-7166] (#2674)
* fix

This resolves the issue with clients not keep track of changes to the layer weights.

* test

Validates the fix to assure clients receive weight updates and track them in order to be able to apply changes when needed.
2023-08-23 23:50:49 +00:00
Noel Stephens 422aa239ed
fix: NetworkTransform synchronization fixes and owner authoritative performance improvement on server-host [MTT-6971] (#2636)
* fix

This resolves an issue with half float precision not synchronizing properly when running in owner authoritative mode, the owner client sends an update to the host-server, the host-server then forwards the state update to the remaining clients at the end of the frame but during the initial processing of the state update the delta position value is collapsed into the full float position due to exceeding the maximum delta. The primary issue was the order of operations that occurred using NetworkVariables to update the transform state when in owner authority mode.

This also reduces the amount of serialization and processing a host has to perform when receiving owner authoritative updates and there are 2 or more remote clients connected (i.e. it has to forward the result to the other clients).  Now, it just forwards the message payload to the non-owner clients upon receiving the state update.

This also fixes:
- an on-going issue with scale where really the answer was to send both the lossy and local scale values when synchronizing and/or teleporting and letting the client-side determine which to use depending upon whether the NetworkObject was parented, was the parenting applied when applying the states, and whether the parenting used WorldPositionStays.

- some minor issues with the parenting test not checking if the NetworkObject was parented before testing the final values.

- updates named message handling slightly so it doesn't spam the log console during shutdown if there are incoming messages while shutting down.

- resolves an issue where you have an owner authoritative NetworkTransform and a host-server with two remote clients connected and the following sequence occurs:
  - Client A connects to the host first and takes ownership of a NetworkObject but does not change the transform state.
  - Client B connects and attempts to move the NetworkObject that Client A owns
  - Client B was able to move the NetworkObject

* test

Adding NetworkTransformStateFlags test to validate the NetworkTransformState flags.
Adding internal BitSet setter and getter for testing and a BitSet flag test.

This test adds a "sub-child" (NetworkObject parented under a child) to the parenting test to add the additional check and make sure that all nested children preserve their values when changed for connected clients and those changes are applied and preserved for late joining clients.

Adding a test to verify that when a late joining client is connected after ownership has been transferred from the host-server to an already connected client and the owner authoritative transform has not changed yet that the non-owner client cannot change the transform values.
2023-08-01 11:51:17 -05:00
Noel Stephens 9af9280d45
fix: NetworkTransform full precision state updates being lost when interpolating [MTT-6799] (#2624)
* fix

This fixes the issue where full precision transform synchronization was losing state while interpolating.

* update

initial change log entry

* update

Adding PR number to change log entry

* fix

Missed including half float precision scale with interpolation enabled since scale only updates the axis that changed (i.e. a target axis value could get stomped otherwise when half precision was enabled...the coming test discovered this).

* test

Modified NetworkTransformMultipleChangesOverTime to use interpolation when 3 axis are being tested as well as added the additional logic required to catch the issue not caught by this test where a state update could stomp a single axial value if the target value had not yet been reached.
2023-07-14 11:18:00 -05:00
Noel Stephens 2b92028b5e
fix: Nested NetworkTransform synchronization fails when parent has non-Vector3.one scale [MTT-6304] (#2538)
* fix

This fixes an issue with interpolation causing nonauthoritative NetworkTransform instances to not properly reflect the final axis values when parenting changes.

* test

Updating the parenting test to validate the fix for parenting a nested NetworkTransform and assuring that values are the same.

* fix

Handle the condition that no new states have been pushed for a late joining client.
(i.e. it just synchronized a nested NetworkTransform and that is it)

* test

Did an overhaul on the parented NetworkTransformTest (formerly NetworkTransformParentedLocalSpaceTest), renamed it to ParentedNetworkTransformTest, and now it tests both world and local space values depending upon how the NetworkObject is parented.

* style

removing commented out code.

* update

Adding entry to changelog

* fix

Migrating SetStateInternal into the Initialization method so it handles change of ownership.
2023-05-18 17:26:34 -05:00
Kitty Draper 8df4e988ed
chore: Merge release/1.4.0 back to develop (#2527) 2023-04-25 21:09:37 +01:00
Noel Stephens 4ebfb5f59b
fix: NetworkAnimator not detecting and synchronizing cross fade initiated transitions (#2481)
* fix
For client authoritative, the server now actually sends any pending animation updates to any non-authoritative clients.
Trigger not updating properly on server when server authoritative but was the owner sending the trigger update.
Improve detection of the type of animation state change.
This fixes the issue where cross fades were not being handled by NetworkAnimator.
This is a first pass fix and the serialization could use an overhaul to reduce bandwidth costs.

* update
Making sure we don't toggle between transition and crossfade.
Packing values for AnimationState
Updating the manual test used to get cross fading to AnimationStates without transitions working.
Making the serialization of the two bools one byte instead of two bytes.

* test
Adding some cross fade tests to the NetworkAnimatorTests.
Also fixed an issue with the coroutineRunner being destroyed before the IntegrationTestSceneHandler was.
This is the final test for cross fade initiated transitions and whether it is detected and synchronized or not.
2023-04-05 09:57:52 -05:00
Kitty Draper bf8929c27b
feat: time mocking (#2472)
* feat: time mocking

* time mocking in NetworkTransformTests

* More mocks.

* Disable LogAllMessages in DeferredMessagingTests

* Standards

* Allow UnityTransport to create its own IRealTimeProvider if no NetworkManager is provided to it.

* XMLDoc updates

* Changed IRealTimeProvider to internal

---------

Co-authored-by: Fatih Mar <mfatihmar@gmail.com>
2023-03-27 18:33:39 +01:00
Fatih Mar 69b06c20f6
style: order modifiers 2023-03-25 13:07:02 +03:00
Fatih Mar 781c251db7
style: enforce more modern language features when available 2023-03-25 12:49:39 +03:00
Fatih Mar 6796eae124
style: stricter using directives sorting 2023-03-25 12:35:33 +03:00
Noel Stephens 39f9a1c8c4
refactor: use unity.mathematics.half in place of added types (#2473) 2023-03-25 08:09:08 +00:00
Noel Stephens 9dbaf06e17
fix: remove added parameter onsynchronize (#2471)
* fix

Removing the added OnSynchronize parameter and using a protected property to avoid major version change.

* test

updating test
2023-03-23 20:37:05 +00:00
Noel Stephens e0e0098ef1
fix: integration tests and NetworkTransform teleport issue (#2451)
* Test Updates and Fixes
Adding UNITY_INCLUDE_TESTS define checks for integration tests
Some modifications to reduce the over-all NetworkTransform test times.
Reducing NetworkAnimator tests time.
Making sure NetworkAnimatorTests.ShutdownWhileSpawnedAndStartBackUpTest fails if the client cannot reconnect after shutting down.
Improving the nested network transform test accuracy and assuring that we are actually comparing against the authority's pushed position and not comparing values in-between ticks.
Making sure all clients are disconnected before shutting down server in NetworkAnimator (trying to see if I can get it more stable on Mac 2020.3)
This update provides a new TimeOutHelper derived class TimeoutFrameCountHelper that requires the expected number of frames to pass and the time out period to be reached before it considers the condition check timed out.
Making 2020.3 Mac OS X runs use a higher threshold as it fails on full precision when interpolation is enabled.
Making the test component for TransformInterpolationObject derive from NetworkTransform to assure that we are checking values after they have been updated.
Updated TransformInterpolationTest to be based on frames and not time.
Making adjustments for systems that run below (or well below) the expected frame rate.
Adding some additional checks as well as providing additional information about time and frame count in NestedNetworkTransformTests.

* fix
Fixing some tests and NetworkTranaform teleporting issue where some deltas could be lost in-between ticks.
Fixing an issue with the network config hash internally stored value not clearing when the server-host or the client shutsdown in the event that prefabs change depending upon the network session being connected to.
2023-03-16 19:46:27 -05:00
Noel Stephens 08005ff821
feat: quaternion synchronization, delta position, and NetworkTransform bandwidth optimizations (#2388)
* update
Quaternion Synchronization: Added the ability to synchronize by quaternions (full precision). Using quaternion synchronization is recommended for scenarios where multiple axis of rotation can change and the transform in question is within a parent-child hierarchy. When enabled, per axis rotation flags are no longer visible in the editor as the entire quaternion is synchronized when any change in rotation occurs.
Quaternion Compression: Added the ability to compress quaternions (requires Quaternion Synchronization to be enabled). Reduces the cost of quaternion synchronization down to 4 bytes at the cost of additional loss in precision (a bit less precise than half float precision).
Half Float Precision: Added the ability to enable half float precision which reduces payload size per instance by ~50% at the cost of a decrease in precision.
Delta Position Synchronization: When using half float precision NetworkTransform uses delta position synchronization to assure any loss in precision is recovered/handled in the next state update.
Added additional virtual methods to be used in prediction calculation scenarios where knowing the exact values being updated are required. This addition includes changing NetworkTransformState to public.
Added a bandwidth optimization related property, SynchronizeTransform, to NetworkObject that allows users to disable the automatic synchronization of the associated transform to reduce the total bandwidth cost of spawning and late joining client synchronization. This is particularly useful if the NetworkObject is used more for management related tasks and has no spatial synchronization needs.
NetworkTransform now only sends the network tick as opposed to the double precision server time since authority updates state only on each new network tick.
NetworkTransformState header properties are now being bit compressed.
Added additional check to make sure if SyncPosition axis value changes while using half precision (delta position) that if the delta on that axis exceeds the maximum delta that the NetworkObject is teleported on the tick this condition is detected.

* test manual

Added a manual test for long-duration testing of delta position compression with precision loss compensation.
Updated the manual nested network transform test using delta position with the HalfVector3 struct.
Added updates to the nested NetworkTransform manual test to be able to visually see that all automated player instances are in the same relative grid regions.
Updated manual tests for additive scene loading manual test with NetworkPrefabPool in order to be able to test turning on and off half float precision, quaternion synchronization, and quaternion compression.
Updated the delta position long duration test for precision drift so that it randomly selects x,y,z axis for direction and synchronization in order to determine if enabling and disabling which axis should be synchronized during runtime can cause issues.

* test 

Added fixes to an issue with the NestedNetworkTransform test.  
Removed the sphere collider from the NetworkTransformOwnershipTests because the test basically ignores collision with other players and collision is not a factor of this test.
Added a new IntegrationNetworkTransform for testing purposes.
2023-03-10 23:25:59 +00:00
Noel Stephens 8b8825b278
fix: NetworkAnimator generating AnimationCurve warnings (#2416)
* fix
Don't try to access m_Animator if it is not assigned.
Don't try to update animation curves.
Now generate a tracking list for all parameters and cull out those controlled by AnimationCurves when checking for deltas.
2023-03-02 02:52:18 +00:00
Noel Stephens 5f1b0ed2cc
fix: NetworkAnimator not synchronizing changes to layer weights (#2399)
* fix
This resolves the regression bug where layer weight updates were not being synchronized if no state transition was occurring.

* test
Adding test to verify layer weight changes are updated for connected clients and that late joining clients are synchronized to the updated weight value.

* test manual
Adding small manual test adjustment to verify the change in a layer weight is synchronized.
2023-02-01 19:10:38 -06:00
Fatih Mar 3d2c266a4d
refactor: reorganize `InternalsVisibleTo` directives in `AssemblyInfo.cs` files (#2387) 2023-01-18 14:47:34 +00:00
Noel Stephens 4cd50923aa
fix: NetworkAnimator destinationStateMachine exception [MTT-5083] (#2309)
* fixes
This fixes the issue where NetworkAnimator was not taking into consideration `AnimatorStateTtansition.destinationStateMachine`.  Now, NetworkAnimator parses each destinationStateMachine's states for trigger transitions and includes those in the transition table.
passing setTrigger bool to internal method.

Fixed issue where the host client was receiving the ClientRpc animation updates when the host was the owner.

Fixed an issue with using pooled objects and when specific properties are cleaned during despawn and destroy.

This fixes the issue where NetworkAnimator was checking for animation changes when the associated NetworkObject was not spawned.

* update
Removed the AnimationSynchronizationData class as it really was not needed.
Adding UNITY_INCLUDE_TESTS define in the components AssemblyInfo.cs file.
This includes some updates to NetworkAnimator that will remove the need to synchronize client's using RPCs but instead use the new OnSynchronize method.

* test manual
Updated the NetworkAnimator manual test that provides a way to validate this fix visually.
Minor fix for weapon attack option in manual test.

* test
Updating test to validate states defined within a destinationStateMachine are triggering.

Made components visible to testproject again although I might try to figure out a better way to handle these two ways of testing.

Updated the NetworkAnimatorTests to acquire the state info from NetworkAnimator.SynchronizationStateInfo.

Co-authored-by: Unity Netcode CI <74025435+netcode-ci-service@users.noreply.github.com>
2023-01-12 20:45:54 +00:00
Kitty Draper b007fbd038
feat: Prefab QoL [MTT-5116] (#2322)
feat: Prefab QoL

Moves prefab list to a ScriptableObject and makes it publicly accessible to be programmable. Credit for most of the work goes to @JesseOlmer, I provided some refinements and testing (including unit tests)
2023-01-11 13:26:27 -06:00
Noel Stephens ade8ce53c4
refactor: NetworkTransform.SetState shouldGhostsInterpolate parameter [MTT-4462] (#2228)
* refactor
MTT-4462
Renaming shouldGhostsInterpolate to teleportDisabled for better clarity of what that parameter does.  While renaming it to isTeleporting would make more sense, that could potentially become a breaking change, and so the next best parameter name would be "teleportDisabled" which would not break users that use this parameter currently.
2022-12-02 19:44:57 +00:00
Noel Stephens 4487baa1d4
feat: Nested NetworkBehaviour Synchronization [MTT-5024] (#2298)
* feat 
This includes the changes to provide users with a way to synchronize NetworkBehaviours with custom data prior to their associated NetworkObject is spawned.

* fix and refactor
This updates NetworkTransform so that it will properly synchronize when placed on nested NetworkBehaviours (i.e. their GameObject has no NetworkObject component).
This also includes some fixes that allows for NetworkObjects to fail, NetworkVariables to fail, and NetworkBehaviour synchronization to fail without impacting the rest of the synchronization process.
Minor fix for in-scene placed parenting under a non-NetworkObject to prevent from being added to the orphaned child list.

* test
Renamed NetworkObjectSceneSerializationTests to NetworkObjectSynchronizationTests.
Added a more robust/wider range of tests, also added running host or server as well as added a basic OnSynchronize test.
Added integration test to validate nested network transforms synchronize properly with nested GameObjects' transforms.
Fixed an issue with late joined clients not registering all players in NetcodeIntegrationTest.

* test manual
This include a nested NetworkTransform manual test to visually validate the nested NetworkTransform update.
2022-11-16 04:48:32 +00:00
Noel Stephens 73ac14155f
fix: NetworkManager ApprovalTimeout should not depend upon client synchronization (#2261)
* fix
This fix separates the IsConnectedClient from the approval process by adding an IsApproved flag.
This also has a fix to prevent the domain backup error during serialization.

* test
Added the ability to bypass the entire NetcodeIntegrationTest connection approval process after the server and clients have been started.  This allows us to now use NetcodeIntegrationTest for unique connection oriented tests without being bound to the asserts if not all clients connected properly.
Refactored for ConnectionApprovalTimeoutTests to use the added m_BypassConnectionTimeout to bypass the waiting for clients to connect. It still uses the message hook catch technique to simulate the timeout scenarios where either a server detects a transport connection but never receives a connection request or a client sends the connection request but never receives approval for the connection.
2022-10-17 21:19:45 -05:00
Noel Stephens e9d94544b7
fix: NetworkAnimator rising RTT issue (#2236)
* fix
This fixes the issue where NetworkAnimator was not completely updated to the changes with AnimationMessage.  NetworkAnimator will now only send states that have changed.
Removed the check for AnimationMessage.AnimationStates being null as it will always be null when deserializing.
Updated several comments for readability and clarity.

* test
adding additional checks to assure or AnimationStates list does not increase in size over time.
2022-10-05 20:32:18 +00:00
Noel Stephens 64c43315cf
fix: Parenting does not preserve WorldPositionStays option and other parenting related issues (#2146)
* fix
Parenting:
Fixed the issue where WorldPositionStays was not being synchronized with clients.
Removed m_IsReparented and associated properties.
Added world position stays parameter to CreateLocalNetworkObject to preserve worldPostionStays.
This fixes some edge case scenarios and issues with parenting in-scene placed NetworkObjects.
One in particular is to provide the local space position and rotation in ParentSyncMessage if the WorldPositionStays value is false.  The server might maintain the original local space values and upon being reparented it re-applies the local space values.  This is only pertinent if the user decides they don't want to use a NetworkTransform for the NetworkObject in question.
Now, a users can control what the final position, rotation, and scale of a NetworkObject is when being added/removed to/from a parent's sibling list ("parented or de-parented").
Parenting and Scale:
Fixed issue where GetMessageSceneObject wasn't using the NetworkObject's lossy scale value.  This would result in improper scaling of parented (WorldPositionStays = true) child NetworkObjects for late joining clients.  Added comments with details on this.
Fixed edge case scenario where nested in-scene placed NetworkObject children are de-parented and then a client late joins. Under this scenario (only for in-scene placed NetworkObjects) we want the late joining client to remove its parent, then set the transform values, and then get spawned.

NetworkTransform:
Fixed issue where TryCommitTransformToServer was not honoring the NetworkTransform.InLocalSpace property.
Fixed issue where teleporting did not honor the NetworkTransforms's current synchronize axis settings.
Removed the private m_TickFrequency property as it is no longer being used.

* refactor
CreateLocalNetworkObject now just accepts the NetworkObject.SceneObject structure as opposed to the 10 properties of the NetworkObject.SceneObject structure passed in as parameters.
Provided the ability to invoke NetworkObject.TrySetParent with a null value in order to be able to remove a parent while also selecting whether they want WorldPositionStay to be true or false (when removing a parent WorldPositionStays impacts the final transform values and can lead to scale issue if you parent with WorldPositionStays set to false and then it remove the parent with WorldPositionStays set to true).
Consolidated the CreateLocalNetworkObject's assignment of the transform values, parenting, and DDOL migration.
Removed parenting from CreateLocalNetworkObject
Removed setting the cached parent directly within SpawnNetworkObjectLocallyCommon as this is done within NetworkObject.ApplyNetworkParenting.

* add
Added RemoveParent to the ParentSync message.
Added applying scale to CreateLocalNetworkObject.
Added parent child sorting to the SceneEventData's synchronization serialization process.
Added the TryRemoveParent helper method to make removing a parent easier.  Without this method users will have to use TrySetParent and cast the null value to either GameObject or NetworkObject.

* test
Added ParentingWorldPositionStaysTest:
Testing with and without WorldPositionStays while also varying child position, rotation, and scale values.
Validates scale with multi-generation nested children where most of the parents have a scale other than Vector3.one. 
Created abstract IntegrationTestWithApproximation to avoid replicating the exact same set of Approximately methods.

Added ParentingInSceneObjectsTests:
This includes all of the scripts and assets that the ParentingInSceneObjectsTests needs.
It includes adding the ParentingInSceneObjects scene to the scenes in build list as well.
This also verifies an in-scene placed NetworkObject parented under a GameObject will preserve that hierarchy.

NetworkTransformStateTest:
Updated the bool parameters to be more meaningful named enums so you know what exactly is being tested.
Added additional NetworkTansformState.IsTeleportingNextFrame logic to the existing test.
Added an additional "step" which verifies the NetworkTransformState is additively collapsing for each detected axial delta over the relative threshold value.

Co-authored-by: Jesse Olmer <jesseo@unity3d.com>
Co-authored-by: Unity Netcode CI <74025435+netcode-ci-service@users.noreply.github.com>
2022-10-05 00:25:18 +00:00
Noel Stephens f98e7a2d80
fix: client authoritative NetworkAnimator skips sending to 2nd player when in server mode (#2127)
co-authored-by: Vadim Tsvetkov
co-authored-by: Andrei Soprachev
* fix: animator syncronization for >2 clients
* fix: remove redundant rpc call when host
* test
This includes coverage for running in server mode only as well as validates the fix where a second client will receive updates.

co-authored-by: Noel Stephens - Unity
* fix
Fixed some additional issues with trigger synchronization.
Removed the bool from ProcessAnimationMessageQueue as it was no longer needed.

* fix
This is a new approach to synchronizing transitions with late joining players without having to actually set the associated conditional trigger.  By building a small list of all states and then building a quick lookup table, we can just synchronize the "transition state" which for late joining clients is a cross fade between the start and destination state.  We synchronize the normalized time (where it was in the transition on the server side when the client connected) of the transition this way as well. Now, we just synchronize states (which some can be transition states).

* test
increased number of clients
Fixed issue where the late joining client was not being shutdown at the end of the LateJoinSynchronizationTest.

* update
NetworkAnimator uses ISerializationCallbackReceiver to build its transition to states table for late joining client synchronization when a transition is ocurring.

Co-authored-by: Vadim Tsvetkov <florius0@ninsar.pro>
Co-authored-by: Andrei Soprachev <soprachev@mail.ru>
Co-authored-by: Unity Netcode CI <74025435+netcode-ci-service@users.noreply.github.com>
2022-09-28 18:18:53 +00:00
Jeffrey Rainy c5dff6d3fd
perf: performance improvements MTT-4641 #2176 (#2204)
* Performance Improvement

- Merge if else into return
- Merge .rotation and .position into .SetPositionAndRotation
- Remove .ToString() call on strings
- Use TryGetComponent to reduce garbage allocation
- Merge .Where().Count() calls into .Count() call
- Remove indirect gameObject call 
- Remove redundant null check
- Use native .Count instead of LINQ method
- Use faster string comparison

* style: adjusting to code standards

Co-authored-by: smitdylan2001 <dylan.smit01@gmail.com>
2022-09-23 13:23:31 +00:00
Jesse Olmer 06f73020e0
fix: Update Add Component menu structure [MTT-4078] (#2191)
Put netcode components into a common sub-folder of the Add Component menu, and also fixed word spacing inconsistencies in the entries
2022-09-19 11:23:10 -04:00
Noel Stephens fdebb55167
fix: Set state private RPC handlers were not honoring local vs world space assignment of position and rotation (#2203)
* fix

SetStateClientRpc and SetStateServerRpc were not updated to use SetStateInternal which honors local vs world space transform setting.s

* update changelog

* test

Modified existing tests to include testing SetState which validates the changes made to NetworkTransform.SetState and associated private methods.

* update

adding the PR number to the changelog entry.

* test

removing conditional check that was not needed.

* update

adding further clarity as to where the two rpc methods were located.
2022-09-14 18:19:12 +00:00
Noel Stephens 20ad052623
fix: NetworkTransform was not ending extrapolation for some states. [MTT-4521] (#2170)
* update

working version that needs clean up

* update

Some touch ups and adjustments to the fix for the extrapolation issue.

* style

adding some minor comments

* update

Added comments and renamed a property.

* update

some code clean up and additional comments

* update

MTT-4521
updating changelog file

* update

MTT-4521
Renamed StopExtrapolatingLastState to TryToStopExtrapolatingLastState.

Added/adjusted comments.

* update

Applying suggested changes.

* update

removing some changes I made while testing out extrapolating past the target.
adjusted comment.

* style

adjusted comment for clarity purposes.

* test

Adding some of the tests.  Still WIP, but wanted to see how the first completed test fairs in Yamato and on consoles.

* style

removing unused namespace.

* test update

Added a form of tick synchronization prior to making changes to the authoritative transform state.

* style

adjusting comments.

* test

- Added NetworkTransformParentedLocalSpaceTests with associated helper methods, components, and properties.
- Added an "Authority" suffixe to the Authority enums for better clarity when looking at the tests within test runner.
- Updated/added additional comments

* style

Making NetworkTransformParentedLocalSpaceTests singular (NetworkTransformParentedLocalSpaceTest)

* style

adding remarks around comments

* style

splitting the comment into a summary with remarks.

* style

updating a comment on the UpdateAuthoritativeState method.

* fix

Copy paste issue.
(need to revisit tests to see why they didn't catch this)

* fix

z component

* fix

using the eurlerAngles... that section of code was a mess!
(sorry!)

* update

Just adding some parenthesis per Kitty's suggestion.

* update and fix

Updated ApplyAuthoritativeState so that it is less complicated to follow.
Fixed another issue discovered where the replicated network state values were being used for resetting interpolators during spawn initialization.  Since the replicated network state only has the most recent deltas at the time the NetworkObject is serialized, this would cause "seemingly random" late joining issues.

* test update

This validates the issue with the more recent updates that revealed the network state only having the most recent deltas and not the full transform state.  This resulted in various "seemingly" random late join transform synchronization issues (specifically the scale that is not being synchronized when spawning NetworkObjects).

* update

removed the unnecessary else if (useInterpolatedValue) condition and re-organized it such that it checks to see if it needs to apply interpolation or just depends upon the state to apply the values directly.

Added additional comments about this area of the code and future improvements.

* fix

Removing unclamped slerp and lerp due to a few timing related issues.  These issues should be solved before re-enabling any form of unclamped lerping/slerping with BufferedLinearInterpolator.

Added additional comments in some areas to be investigated for a potential fix.

* fix

temporarily disabling two editor based interpolator extrapolation based tests until I can refactor them to not take extrapolated values into consideration.

* fix

removing debug code used to verify NetworkTransform is not the only thing within NGO that fails when dropping packets (most likely to occur 20-30% drop rate).

* fix

Make sure to initialize based on whether it is set to world or local space.

* fix

When authority is applying the current position and rotation during OnNetworkSpawn, use the appropriate local vs world space values.

* update

Adding another fix to the change log

Co-authored-by: ashwini <36935028+ashwinimurt@users.noreply.github.com>
2022-09-08 15:46:30 +00:00
Noel Stephens 28109b4227
fix: NetworkTransform teleport interpolating from last position on non-authoritative side [NCCBUG-166] (#2110)
* fix

NetworkTransform was setting the value of m_Bitset but not resetting the individual bits if there was no deltas.  This would result in a gradually increasing message size over time when updating the NetworkTransform.

* update

migrating the assignment back down below the CanCommitToTransform

* fix

This resolves the issue where clients were applying every value marked to be synchronized even if the update didn't include specific axis values.

* test

This includes some fixes to prefabs that hadn't been updated to the more recent changes in NetworkTransform that limited the minimum threshold (i.e. they were set to 0 which causes issues)

* fix

Since we are now no longer sending the entire transform values, this addition prevents the non-authoritative side from making changes to the transform.

* style

removing whitespace

* update

Adding some test adjustments and including rotation to interpolation measurements.

* style

removing an unused namespace.

* style

fixing issue with reference to UnityEngine's Object after I removed the system namespace.

* fix

This includes the adjustments for client authoritative mode to work without sending RPCs.

* fix

This update fixes the issue where the authoritative side was interpolating when interpolate is enabled.
Now, the authoritative side no longer interpolates.

* manual test updates

These changes make the player client authoritative within the Samples Menu->Additive Scene Loading manual test/sample.

* update

reverting the change of m_Bitset to an internal.

* test update

updating test to account for reverting back to the private m_Bitset.

* update

Migrated the code that updates interpolators with the current value if the axis is not set into the AddInterpolatedState method as opposed to it being in the ApplyInterpolatedNetworkStateToTransform

* fix

First pass fix for teleporting.

* test manual

Manual test adjustments (still working on player motion controller from client side)

* manual test

Adjustments for the teleporting sample/manual test.
Still working on the new player cube motion model.

* test manual

Improved motion model (still could use some more work for client to server side).
Now packing data sent from client to host/server.
Added UI text that displays whether the instance is a server, host, or client.

* update

removing debug code

* fix

This fixes the last issues with teleporting and the updated player motion model.

* fix

Cleaning up how we handle transitioning to and from global and local space.
Minor adjustment to the validation test to assure the range of error being tested on the client side is the same as the delta position threshold range.

* update

Removing the NetworkTransformState Position, Rotation, and Scale since we are only sending the values that changed (i.e. if the x-axis of position was the only thing that was set and NetworkTransformState.Position was used, then the Y and Z axial values would be invalid).

* fix

removing code block no longer needed.

* style

removing a comment that was no longer needed.

* update

applying suggested changes

* update

replacing the GetReplicatedNetworkState() method with a getter ReplicatedNetworkState property.

* update

This is a new approach:
- Make in-between state updates additive
- Clear our state's Bitset value and prepare to capture any deltas for the next network tick period.

* update

Realized since we are back to additive (per network tick), we can now remove the non-authoritative interpolation work around for not having all values that changed within the associated NetworkTransformState's network tick period.

* update

Disposing the NetworkVariables when the NetworkTransform is destroyed.

* update

Suggestion updates and comment fixes.

* style

adding Sam's comment.

* style

updated comment to include what we are preserving.

* update

Removing the ApplyTransformValues and SetTransformValues as they are no longer needed.
Also, removing the associated properties.

* Test Manual

Updates to manual test related assets and scripts.
Removed the "make a pooled object invisible to hide the teleport interpolation issue" hack that would disable the render mesh when despawned and enable it shortly after it is spawned.
Increased tick rate to 32 in the additive scene loading test.
Fixing white space issues.

* update

Removing the unused serverTime addition as well.

* update

Renamed ApplyInterpolatedNetworkStateToTransform to ApplyAuthoritativeState.
(It didn't make sense if interpolation is disabled)

* tests update

This includes an updated NetworkTransformTests that tests both authority types while running in Server and Host modes.
This includes some updates to naming for easier identification of what each test does (in test runner and in code).

* Update

Minor adjustment where we don't need to send a local properties over the stack via parameters.

* test

Added interpolate enable/disable values to all tests.
Now, all NetworkTranaformTests are done with interpolation enabled and disabled.

* fix and update

Fixed another issue that was exposed while cleaning up the code base.
Was able to remove even more of the code added previously.
Some clean up as well as making one additional method private as opposed to protected to prevent us from having to release a minor version vs patch.
Also,  ApplyTransformToNetworkState, and ApplyTransformToNetworkStateWithInfo only return if the state is dirty (the rest can be determined from within the state itself).

ApplyLocalNetworkState, used for integration tests, now just returns the NetworkTransformState.

* fix

This fixes the issue with the memory leak message in the editor NetworkTimeTests  (very odd this fixed the issue).

* test manual

Switched over to an owner authoritative NetworkTransform that also includes the playermovement.
Adjusted the PlayerCube NetworkPrefab and minor adjustment to the CollideTeleporter.

* update

updating the changelog

* fix

Found a minor logic issue in ApplyTransformToNetworkStateWithInfo where the state dirty flag could be reset before end of the current network tick.  This could result in state being carried forward into the next network tick.  This resolves that issue.

* update

Minor adjustment to how we handle applying a rotation measurement on the non-authoritative side.
Removed a property not being used outside of a single method and added additional comments to the PlayerMovement component.

* update

This update includes the final changes required in order to support the previous NetworkTransform model where it was always server authoritative and client owners could direct/apply state via internal RPCs.  This also includes the ability for a server to apply/dictate state when running in client owner authority mode.

This includes updates to the NetworkTransform tests that validate all of these updates and increase the amount of coverage for NetworkTransform.

* style

moving new private m_ClientRpcParams and m_ClientIds up to the rest of the property declarations.
Adjusting comment

* test manual

Minor adjustments for the random player movers.
Applying the server authoritative player prefab back to be the default for the additive scene sample (this makes it easier to compare to main branch).

* style

removing a no longer needed comment.
adding note about future clean up for NetworkTransform.

* style

fixed spelling issue

* style

removing left over comment and spelling

* style

removing legacy/unused namespaces

* update

realized our CommitLocallyAndReplicate method was serving no purpose at this point.
added the assignment of NetworkTransformState to the ReplicatedNetworkState within TryCommit and removed CommitLocallyAndReplicate.

* update

removing legacy check for TryCommitTransformToServer that is no longer needed.

* update

removing m_Transform (no purpose for it)
Fixing minor grammar issue with a comment

* test manual update

removing additional IsOwner check.

* revert

reverting the changes I made to the editor test NetworkTimeTests as I just had Yamato crash again in a different area in NetworkTimeTests with the same memory leak error.

* style

replacing LF/CR

* Style

Improving comments
2022-08-18 13:00:30 -05:00
Noel Stephens 2d9f786198
fix: NetworkAnimator Synchronizing transition twice [MTT-3564] (#2084)
* fix

This fixes the issue where transitions were being both triggered and the change in animation state (i.e. transition state) was being synchronized and applied to clients already transitioning which would cause any StateMachineBehaviours to have their OnStateEnter method invoked twice.

* fix

Making adjustments to account for changes to the Transition state update vs trigger update fix.

* test

Adding the additional StateMachineBehaviour (CheckStateEnter) to validate this fix.
Adjusting two tests for this fix.
Includes the animation related assets needed for the test.

* style

adding additional comments for some changes that were not obvious to the fix.

* update

removing code used to debug

* style

MTT-3564
updating changelog.

* style

correcting grammar in comment

* style

slight adjustment to the comment

* style

* update

removing more debug related code.

* style

minor integration test variable rename.
2022-08-17 17:00:45 -05:00
Noel Stephens 105bbe2be6
fix: NetworkAnimator fails to synchronize end of animation loop for late joining clients [MTT-4060] (#2076)
This resolves the issue where animations at the end of their loop would not be synchronized with late joining clients.
2022-07-27 01:01:13 -07:00
Noel Stephens 9aff85f4e7
fix: API Audit for missing XML documentation [MTT-3881] (#2026) 2022-06-27 21:49:59 +01:00
Noel Stephens d23f93dba5
fix: NetworkAnimator does not work using the server authoritative model [MTT-3745] (#2003) 2022-06-09 12:01:04 +00:00