Skip to content

feat: Nested NetworkBehaviour Synchronization [MTT-5024] #2298

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

Merged
merged 33 commits into from
Nov 16, 2022

Conversation

NoelStephensUnity
Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity commented Nov 7, 2022

This refactor provides users a way for synchronizing nested NetworkBehaviours.
It also fixes an issue with the serialization pipeline where if a NetworkObject fails to synchronize it will not halt the entire synchronization process.

  • This also resolves the issue where nested NetworkTransforms were not being synchronized.
  • When variable length safety is disabled it does not use an unsigned short to define the size written per NetworkVariable.

MTT-5024
Associated reports of this issue:
https://discordapp.com/channels/449263083769036810/1033497351475699712/1033497351475699712
https://discordapp.com/channels/449263083769036810/1034802372880375828/1034802372880375828

Changelog

  • Added: Protected method NetworkBehaviour.OnSynchronize which is invoked during the initial NetworkObject synchronization process. This provides users the ability to include custom serialization information that will be applied to the NetworkBehaviour prior to the NetworkObject being spawned.
  • Fixed: Issue where NetworkTransform components nested under a parent with a NetworkObect component (i.e. network prefab) would not have their associated GameObject's transform synchronized.
  • Fixed: Issue where NetworkObjects that failed to instantiate could cause the entire synchronization pipeline to be disrupted/halted for a connecting client.
  • Fixed: Issue where in-scene placed NetworkObjects nested under a GameObject would be added to the orphaned children list causing continual console warning log messages.
  • Changed: When NetworkConfig.EnsureNetworkVariableLengthSafety is disabled NetworkVariable fields do not write the additional ushort size value (which helps to reduce the total synchronization message size), but when enabled it still writes the additional ushort value.

Testing and Documentation

  • Includes integration test updates and additions

This includes the changes to provide users with a way to synchronize NetworkBehaviours with custom data prior to their associated NetworkObject is spawned.
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.
An updated version of this test that includes additional tests related to the refactoring.

This test was not properly testing the entire serialization pipeline and it only tested for one NetworkVariable.  If you added another NetworkVariable to the NetworkBehaviourWithNetworkVariables component the synchronization process would halt.  There was also a bug in SceneEventData that would occur if a NetworkObject failed to be instantiated. The updates included resolve all of these issues for the original intention behind the test.
This updates NetworkTransform so that it will properly synchronize when placed on nested NetworkBehaviours (i.e. their GameObject has no NetworkObject component).
This include a nested NetworkTransform manual test to visually validate the nested NetworkTransform update.
Minor fix for in-scene placed parenting under a non-NetworkObject to prevent from being added to the orphaned child list.
minor camera related updates to the nested NetworkTransform manual test.
finishing a comment
Updated comments, formatting, and organizational related issues.
compilation issue.
variable name and comment adjustments.
Yamato really doesn't like that conditional even though it compiles just fine.
white space removal
MTT-5024
updating changelog with the addition, fixes, and change
Minor updates to some manual test assets.
fixing some minor merge issues with the byte packing updates.
removing whitespaces that somehow made their way in when merging.
Renamed NetworkObjectSceneSerializationTests to NetworkObjectSynchronizationTests.
Added a more robust/wider range of tests, also added running host or server.
Fixed an issue with late joined clients not registering all players in NetcodeIntegrationTest.
Integration test to validate nested network transforms synchronize properly with the nested GameObjects' transforms.
removing unused const string value.
@NoelStephensUnity NoelStephensUnity marked this pull request as ready for review November 9, 2022 22:02
@NoelStephensUnity NoelStephensUnity requested a review from a team as a code owner November 9, 2022 22:02
@NoelStephensUnity NoelStephensUnity changed the title refactor!: Synchronization and Nested NetworkBehaviours refactor: Synchronization and Nested NetworkBehaviours Nov 9, 2022
@NoelStephensUnity NoelStephensUnity changed the title refactor: Synchronization and Nested NetworkBehaviours feat: Synchronization and Nested NetworkBehaviours Nov 9, 2022
@NoelStephensUnity NoelStephensUnity changed the title feat: Synchronization and Nested NetworkBehaviours feat: Nested NetworkBehaviour Synchronization] Nov 10, 2022
@NoelStephensUnity NoelStephensUnity changed the title feat: Nested NetworkBehaviour Synchronization] feat: Nested NetworkBehaviour Synchronization [MTT-5024] Nov 10, 2022
Updated and added comments for readability
Removed whitespace and a local network variable that was not needed.
one last minor adjustment to a comment for better clarity.
>.<
Spelling issue.
Removing unused using directive.
Copy link
Contributor

@jeffreyrainy jeffreyrainy left a comment

Choose a reason for hiding this comment

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

For the record, I have reservation around the direction and the NetworkObject nested restriction. I feel we walked pretty far away from the MLAPI design relying on NetworkVariables and RPC in a pretty uniform fashion.

That said, the PR shows thorough code, properly tested and addresses specific shortcomings. So, let's go with this, but consider marking a bit more clearly "OnSynchronize is optional and only meant to address complex cases where NetworkVariables and RPC fall short"

updating public API xml documentation for NetworkBehaviour.OnSynchronize
@NoelStephensUnity NoelStephensUnity enabled auto-merge (squash) November 16, 2022 03:50
@NoelStephensUnity NoelStephensUnity merged commit 4487baa into develop Nov 16, 2022
@NoelStephensUnity NoelStephensUnity deleted the fix/nested-networktransform-synchronization branch November 16, 2022 04:48
jakobbbb pushed a commit to GooseGirlGames/com.unity.netcode.gameobjects that referenced this pull request Feb 22, 2023
…ologies#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants