Skip to content

refactor: decouple PendingSoftSyncObjects from NetworkSpawnManager #913

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 16 commits into from
Jun 29, 2021

Conversation

NoelStephensUnity
Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity commented Jun 21, 2021

As described in MTT_819, part of the scene management refactoring process includes first removing specific dependencies from other classes. This is the first phase of this process. This task also includes the removal of NetworkSceneManager.IsSpawnedObjectsPendingInDontDestroyOnLoad

Acceptance Tests
The manual scene transitioning tests need to be used for this PR as it was determined specific changes (Phase 3 of the proposal) are required to attempt to write an automated scene transitioning test that covers in-scene placed NetworkObjects and dynamically spawned NetworkObjects.

Additional Updates
Before implementation of the automated unit test, there was a need to update some of the classes and assets used in the existing manual scene transitioning test based on more current changes ( i.e. NetworkTransform requires rigid bodies to be set to IsKinematic on non-owner/authorized clients otherwise they will get errors logged which would cause issues with unit testing).
While I was in the related regions of code, if I noticed misspelled words in comments or the like I included those as well.

This removes NetworkSpawnManager.PendingSoftSynchObjects and replaces it with NetworkSceneManager.ScenePlacedObjects.
The primary difference between the two is that the ScenePlacedObjects is populated immediately after a level is loaded or when being approved and already within the current scene.
Migrating the ScenePlacedObjects dictionary up to the rest of the NetworkkSceneManager's dictionary definitions.
Removing the PendingSoftSyncObjects dictionary from NetworkSpawnManager.
Use the ScenePlacedObjects dictionary to generate the client(s) switch scene stream buffer.

Refactored PopulateScenePlacedObjects method to not set the IsSceneObject to true and to also check and make sure the NetworkObject instance's NetworkManager reference is the same NetworkManager instance as the NetworkSceneManager's NetworkManager instance in question in order to maintain compatibility with the MultiInstanceHelper class for Mult-Instance unit tests.
Renaming OnSceneUnloadClient and OnSceneUnloadServer to OnClientLoadedScene and OnServerLoadedScene
Fixed some remaining checks (player prefab) as to whether the rigid body should be kinematic or not to prevent the mega spam.

During the revert changes of the NetworkTransform changes to better reflect what is in the develop branch, missed the else if.

Fixed a minor issue with the slider in the SceneTransitioning manual test to better visually reflect what the value is as well as handle the scenario if it starts at 0 boxes per second it needed to start the coroutine and if set to zero and the coroutine was running it terminates the coroutine.
This is a fix for the NetworkObjectOnSpawnTest where it was spawning a GameObject twice that contained a component that would throw an exception if you spawned a NetworkObject.
An unintended project version change
Checking to see if Yamato fails on this...
This test verifies that "cleaning in-scene placed network objects" within the connection approved method was hiding potential bugs from other unit tests.
Removing the unit test duplicated GameObject instance and all of the associated code to verify this was how the bug was missed by TestRunner and Yamato.
@NoelStephensUnity NoelStephensUnity marked this pull request as ready for review June 21, 2021 21:23
reverting back to the original values for these 3 files that were mistakenly committed.
@0xFA11 0xFA11 changed the title refactor: MTT_819 decoupling pending soft synch objects from spawn manager refactor: decouple PendingSoftSyncObjects from NetworkSpawnManager Jun 28, 2021
/// -- Before any "DontDestroyOnLoad" NetworkObjects have been added back into the scene.
/// Added the ability to choose not to clear the scene placed objects for additive scene loading.
/// </summary>
internal void PopulateScenePlacedObjects(bool clearScenePlacedObjects = true)
Copy link
Contributor

Choose a reason for hiding this comment

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

minor (personal opinion):

Suggested change
internal void PopulateScenePlacedObjects(bool clearScenePlacedObjects = true)
internal void UpdateScenePlacedObjects(bool clearScenePlacedObjects = true)

}
}

private void OnSceneUnloadServer(Guid switchSceneGuid)
private void OnServerLoadedScene(Guid switchSceneGuid)
Copy link
Contributor

Choose a reason for hiding this comment

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

while you're doing some small refactors here, do you mind renaming all switchSceneGuid and other switchXXX with non-switch versions such as sceneGuid instead of switchSceneGuid? I believe it wouldn't harm the understanding but fix syntax-highlighter getting confused :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will see if there is a better term for this... I ignored some of this stuff because the later phases of the proposal would effectively remove all of that.

@@ -25,9 +25,6 @@ public class NetworkSpawnManager
/// </summary>
public readonly Dictionary<ulong, NetworkObject> SpawnedObjects = new Dictionary<ulong, NetworkObject>();
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we will eventually get rid of NetworkSpawnManager entirely at some point. For instance, SpawnedObjects should probably be managed by NetworkSceneManager since they are properties of scenes. Even if we were to move objects between scenes, they are still "in" scenes. Managing object spawning and instances in 2 (NetworkSpawnManager & NetworkSceneManager) feels a bit weird to me :P

But obv, that's something for later — just wanted to braindump my 2-cents here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, it is weird indeed. This update removes the dependency from NetworkSpawnManager and places it into NetworkSceneManager in preparation for the proposed direction. If we do go in the proposed general direction, then the object synchronization process will be handled differently anyway.... so keeping a list of in-scene NetworkObjects instantiated via scene loading really isn't "handling spawning"... it is just "tracking what was automatically instantiated".

Copy link
Contributor

@0xFA11 0xFA11 left a comment

Choose a reason for hiding this comment

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

overall looking good except for 1 potential bug.
also left some minor comments here and there.

…er.cs

Co-authored-by: M. Fatih MAR <mfatihmar@gmail.com>
Copy link
Contributor

@0xFA11 0xFA11 left a comment

Choose a reason for hiding this comment

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

bug fixed, good enough for me!

@@ -79,6 +79,7 @@ public class NetworkSceneManager
internal readonly Dictionary<string, uint> SceneNameToIndex = new Dictionary<string, uint>();
internal readonly Dictionary<uint, string> SceneIndexToString = new Dictionary<uint, string>();
internal readonly Dictionary<Guid, SceneSwitchProgress> SceneSwitchProgresses = new Dictionary<Guid, SceneSwitchProgress>();
internal readonly Dictionary<uint, NetworkObject> ScenePlacedObjects = new Dictionary<uint, NetworkObject>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to be sure, this functions the same as the previous PendingSoftSyncObjects? So once a scene placed object get spawned it will be removed from this list? Maybe we should call this PendingScenePlacedObjects or UnspawnedScenePlacedObjects if that is the case?

Copy link
Contributor

@LukeStampfli LukeStampfli left a comment

Choose a reason for hiding this comment

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

More decoupling is always welcome!

@NoelStephensUnity NoelStephensUnity enabled auto-merge (squash) June 29, 2021 16:07
@NoelStephensUnity NoelStephensUnity merged commit fae7e8c into develop Jun 29, 2021
@NoelStephensUnity NoelStephensUnity deleted the refactor/MTT-819 branch June 29, 2021 16:20
SamuelBellomo added a commit that referenced this pull request Jul 6, 2021
…ity-Technologies/com.unity.multiplayer.mlapi into test/multiprocess-tests/orchestration

* 'test/multiprocess-tests/orchestration' of github.com:Unity-Technologies/com.unity.multiplayer.mlapi:
  feat: log warning if detected child NetworkObjects under a NetworkPrefab (#938)
  fix: reducing log level for noisy log and adding details for developer log (#926)
  feat: users can set authority on network transform programmatically (#868)
  refactor: move NetworkBehaviour update to a separate non-static class (#917)
  test: add utils for multi instance tests (#914)
  test: downgrading testproject to 2020.3.12f1 (#927)
  refactor: decouple PendingSoftSyncObjects from NetworkSpawnManager (#913)
  chore: Change function signature of OnDespawnObject to accept NetworkObject (#928)
  fix: Empty prefab removal (#919)
SamuelBellomo added a commit that referenced this pull request Jul 6, 2021
…rocess-tests/base-multiprocess-tests

* test/multiprocess-tests/orchestration:
  feat: log warning if detected child NetworkObjects under a NetworkPrefab (#938)
  fix: reducing log level for noisy log and adding details for developer log (#926)
  feat: users can set authority on network transform programmatically (#868)
  refactor: move NetworkBehaviour update to a separate non-static class (#917)
  test: add utils for multi instance tests (#914)
  test: downgrading testproject to 2020.3.12f1 (#927)
  refactor: decouple PendingSoftSyncObjects from NetworkSpawnManager (#913)
  chore: Change function signature of OnDespawnObject to accept NetworkObject (#928)
  fix: Empty prefab removal (#919)
SamuelBellomo added a commit that referenced this pull request Jul 6, 2021
…est/multiprocess-tests/execute-step-in-context

* test/multiprocess-tests/base-multiprocess-tests:
  feat: log warning if detected child NetworkObjects under a NetworkPrefab (#938)
  fix: reducing log level for noisy log and adding details for developer log (#926)
  feat: users can set authority on network transform programmatically (#868)
  refactor: move NetworkBehaviour update to a separate non-static class (#917)
  test: add utils for multi instance tests (#914)
  test: downgrading testproject to 2020.3.12f1 (#927)
  refactor: decouple PendingSoftSyncObjects from NetworkSpawnManager (#913)
  chore: Change function signature of OnDespawnObject to accept NetworkObject (#928)
  fix: Empty prefab removal (#919)
SamuelBellomo added a commit that referenced this pull request Jul 6, 2021
…est/multiprocess-tests/adding-perf-tests-for-spawn

* test/multiprocess-tests/execute-step-in-context:
  feat: log warning if detected child NetworkObjects under a NetworkPrefab (#938)
  fix: reducing log level for noisy log and adding details for developer log (#926)
  feat: users can set authority on network transform programmatically (#868)
  refactor: move NetworkBehaviour update to a separate non-static class (#917)
  test: add utils for multi instance tests (#914)
  test: downgrading testproject to 2020.3.12f1 (#927)
  refactor: decouple PendingSoftSyncObjects from NetworkSpawnManager (#913)
  chore: Change function signature of OnDespawnObject to accept NetworkObject (#928)
  fix: Empty prefab removal (#919)

# Conflicts:
#	testproject/Packages/manifest.json
SamuelBellomo added a commit that referenced this pull request Jul 6, 2021
…to test/multiprocess-tests/adding-doc-on-how-to-use

* test/multiprocess-tests/adding-perf-tests-for-spawn: (22 commits)
  removing comment and adding something a bit more dynamic
  correct spacing
  fix for unused method better comments adding tests to make sure things don't break
  better exception
  using proper list
  using latest test framework
  rename
  apply rename
  should be kept public for following PR
  naming
  Applying suggestions
  Apply suggestions from code review
  consistent naming
  feat: log warning if detected child NetworkObjects under a NetworkPrefab (#938)
  fix: reducing log level for noisy log and adding details for developer log (#926)
  feat: users can set authority on network transform programmatically (#868)
  refactor: move NetworkBehaviour update to a separate non-static class (#917)
  test: add utils for multi instance tests (#914)
  test: downgrading testproject to 2020.3.12f1 (#927)
  refactor: decouple PendingSoftSyncObjects from NetworkSpawnManager (#913)
  ...
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.

3 participants