* feat: Supporting managed types in NetworkVariable.
Also changes NetworkVariable to deserialize INetworkSerializable types in-place - this is done to avoid having a GC alloc every time the value changes. There will only be a GC alloc if it receives an updated value and the current value is null.
Managed types are supported in two ways:
1. By making them INetworkSerializable, or
2. By assigning the delegates UserNetworkVariableSerialization<T>.WriteValue and UserNetworkVariableSerialization<T>.ReadValue
If a managed type is passed in without meeting one of those criteria (or any unsupported type), then an exception will be thrown the first time the NetworkVariable is read or written. That timing is to ensure no weird behavior with exceptions being thrown before user code is able to assign the delegates.
Co-authored-by: Fatih Mar <mfatihmar@gmail.com>
* 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.
* fix: correctly rejecting NetworkList modifications on unauthorized clients. Adding tests for it. Allowing null IEnumerable to mean empty list in NetworkList
* 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>
* fix
Need to track any clients that disconnected to add them to the list of clients that did not complete the scene event.
Reducing the logic used to determine when the SceneEventProgress is finished.
Renamed a few properties and methods for code readability purposes.
Fixed the logic behind determining when the SceneEventProgress should complete.
Renaming the SetSceneAsyncOperation to just SetAsyncOperation.
* refactor
Completely removed the entire SceneEventAction.
Replaced it with an even more simplified version of SceneEventProgress.
We will no longer allocate memory for SceneEventAction.
* style
Added additional comments for clarity
fixing grammar in a comment
removing two CR/LFs
moving a comment above a few lines of code (otherwise it doesn't make sense).
Last comment adjustment
* test
Added several tests to verify that SceneEventProgress will complete if all clients finished the scene event, if clients disconnect while it is still in progress, will time out if one or more clients never finish, and finally will still complete if one or more clients late join while it is still in progress.
* fix
Removed the extra NetworkTransform no longer needed form the PhyscisPlayer prefab since the PlayerMovement class derives from NetworkTransform.
* update
moving the physics sample higher in the list and the sample scene to the bottom.
MTT-4605
* fix
This resolves the issue where clients would not regenerate their NetworkConfig's hash value if a client disconnected from one server and tried to join another server.
* test
This validates that passing false to the NetworkConfig.GetConfig method generates a unique hash value.
* update
updating the changelog entry with the PR number.
* fix
This fixes the issue with player objects not honoring the DontDestroyWithOwner property.
The summary for DontDestroyWithOwner was incorrect. When true the NetworkObject's ownership is given back to the server.
* test
Adding a test to verify that when a client disconnects and the client's player object has DontDestroyWithOwner set to true that the NetworkObject's ownership is transferred back to the client.
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>
* Make BatchedSendQueue dynamically-sized
* Remove MaxSendQueueSize as a serialized field
* Add CHANGELOG entries
* Add PR number to CHANGELOG entries
* Add extra tests for BatchedSendQueue
* Address some PR comments
* Keep the standards checks happy
* Address a review comment + some cleanup
* Adding support for netsim to be able to work with Tools adapter
* Setting up Simulator Pipeline stage if NetSim is available
* Deprecate DebugSimulator when using UTP2
Co-authored-by: Jesse Olmer <jesseo@unity3d.com>
Co-authored-by: DenninDalke <dennindalke@gmail.com>
* fix: Remove "Script" fields from Netcode components in the inspector
* Standards
* standards again
* Fix compile errors in minimalproject
* Whoops, those version defines were for the runtime, had to add them to editor too.
* validator...
* 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.
* chore: websockets. Minimalist UI to use WebSockets
* fix: adjusting #ifdef on transport version to allow building non-webgl platforms with UTP 2.0
* fix: addressing build issue where WebGL platform requires different name for UTP symbols
* fix: emitting a warning and switching to WebSockets if uers don't, on WebGL platform
* Addressing PR review comments
* Addressing PR review comments
* Update com.unity.netcode.gameobjects/CHANGELOG.md
Co-authored-by: Fatih Mar <mfatihmar@gmail.com>
Co-authored-by: Fatih Mar <mfatihmar@gmail.com>
* fix: Use Time.unscaledDeltaTime instead of Time.deltaTime as time step (#2171)
This fixes the case of Time.timeScale = 0 stopping the NetworkManager to update.
This as no influence on all projects that always have Time.timeScale = 1.
+ Add tests
+ Change existing test using Assert.Equal(boolExpr) to the correct Assert function to display real values expected instead of just "true" or "false"
* style: removing unrelated stylistic differences. Fixing brackets placement (netcode.standards)
* test: test adjustments
* test: test adjustments
* test: Applying PR review suggestion of saving the time scale
* test: Applying PR review suggestion of saving the time scale, second location
* Reverted changes to AddNetworkPrefabTests and fixed instabilities caused by NetworkManager.Singleton (can we get rid of that completely soon?)
* reverting unwanted whitespace change
* reducing the test cases to 0.0f, 1.0f and 2.0f timescales
* Revert "Reverted changes to AddNetworkPrefabTests and fixed instabilities caused by NetworkManager.Singleton (can we get rid of that completely soon?)"
This reverts commit 02a222eeee.
Co-authored-by: PitouGames <pitou.games@gmail.com>
Co-authored-by: Kitty Draper <kitty.draper@unity3d.com>
* 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>
* fix: Marking NetworkVariable dirty upon spawn on the host/server. Falls short as the NetworkBehaviour doesn't yet have its NetworkVariables initialized
* fix: clearing variable dirty state post spawning. Also, Initializing NetworkVariable upon spawn, as it is the logical place to do so
* test: tests and removing debug logging
* chore: adding preprocessor define in Netcode for GameObjects, when UTP Transport is 2.0 or above
* chore: adding preprocessor define in Netcode for GameObjects, when UTP Transport is 2.0 or above
* chore: adding preprocessor define in Netcode for GameObjects tests, when UTP Transport is 2.0 or above
* chore: conditional use of UTP 2.0
* style: coding standards
* style: coding standards
* Adding some fixed from PR review comment
* fix: fixing tools package compilation, when used in netcode for gameobjects, with UTP 2.0
* fix: fixing tools package compilation, when used in netcode for gameobjects, with UTP 2.0
* fix: build break for UTP 2.0 builds without tools installed
* fix: fixing build errors with Collection 2.1.0-exp3
Achieves a more GC friendly DrawRay debug code through caching the gameobject transform, reducing the engine calls to getTransform
Co-authored-by: Gustavo Santos <gustappsantos@gmail.com>