Skip to content

Conversation

NoelStephensUnity
Copy link
Contributor

@NoelStephensUnity NoelStephensUnity commented Aug 9, 2021

This is the RFC for MTT-820
Link to view the RFC

Summary
In order for users to be able to effectively use additive scene loading and benefit from multi-scene editing workflows there are some additional features and refactoring needed with NetworkSceneManager.

Acceptance Criteria

  • Scene loading and transitioning (non-additive) still works as expected.
  • Additive scene loading works with:
  • Scene Transitioning
  • Late Joining
  • Network Prefab Overrides
  • Custom Prefab Overrides
  • NetworkObject Pooling

Users should be able to implement various additive scene usage patterns commonly used in Unity today with the only distinguishing differences revolving around the requirements of the NetCode implementation.

This is still a work in progress.  Trying to distinguish between guided and reference level related content.
Adjusted some of the wording.
Still trying to distinguish between guided and reference level...moved everything into guided but I think there should be a better separation still.
Removed legacy Event_
More minor tweaks to language.
minor adjustments to text.
Migrated some sections to the reference level and added some additional code snippets.
finished filling out the last few sections for this rfc.
updated the title.
removing unused images.
Moving some of the reference level stuff around to make more sense.
Resized an image and added some additional text copy.
Minor update in the scene dependency name example
Fixing language and spelling.
Minor update to text copy.
Revised some text copy for better clarity.
spelling.
missing comma
Found legacy SCENE_EVENT reference and updated that to reflect SceneEvent
Added spaces between a period and start of a new sentence.
Updated some of the diagrams that used legacy scene event type names.
Updated some of the text to reflect appropriate scene event type names.
updated a diagram.
adding minor blurb about the re-synchronization process.
minor tweak to the re-synchronization text copy.
update rfc and pr number
Fixed typos and scale for two diagrams.

![](0000-additivescenes-and-networkscenemanager-refactoring/NSM_Reference8.png)

With the existing netcode architecture NetworkObjects are always associated with the currently active scene and are serialized in no specific order nor grouped by any form of scene dependencies. The above diagram outlines one problematic scenario where NetworkPrefabHandler spawn generators are additively loaded in **Scene_A-1** and **Scene_B-2**. On the server or host side, there would be no real issues as the scenes would be loaded in the appropriate order and the NetworkObjects would not need to be synchronized locally. However, on the client side issues arise when NetworkObjects that were dependent upon either **Scene_A-1** or **Scene_B-2** are instantiated before their dependent additive scenes are loaded.
Copy link
Contributor

Choose a reason for hiding this comment

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

However, on the client side issues arise when NetworkObjects that were dependent upon either Scene_A-1 or Scene_B-2 are instantiated before their dependent additive scenes are loaded.

I'm not sure whether this problem needs to be solved by us or not. I'd expect the developer who implements "spawn pools inside additively loaded scenes" to solve this problem for themselves. Though I might be narrowly-minded here.

Copy link
Contributor Author

@NoelStephensUnity NoelStephensUnity Aug 13, 2021

Choose a reason for hiding this comment

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

Yeah, I looked at various possible approaches for this by playing the role of a user and trying various scenarios where a user has a dependency for a NetworkObject that is instantiated in the current active scene (i.e. single loaded mode) by some user code (component) in a NetworkObject/GameObject within an additive scene. I used NetworkObject pools that use custom Network Prefab handlers since that too was a new feature in this milestone (i.e. make sure the two feature play nice with each other). Without the NetworkSceneManager knowing about any form of scene dependencies the issue only arises when a player is joining a game session in progress.
The initial implementation that did not have any form of scene dependency functionality I tried several approaches from the "user code side" and it resulted in a very complex set of code the user would be required to write to detect any NetworkObjects instantiated, determine if they belong to a NetworkObject pool, inserting the NetworkObject into the pool (and releasing the NetworkObject in the pool's position it took), but in the end it ended up being a high user pain threshold that didn't work "smoothly".

The primary issue boils down to order of operations:
When do you instantiate NetworkObjects and should other additive scenes be loaded first before those NetworkObjects are instantiated?

By adding the ability to set a NetworkObject's scene dependency and making the NetworkSceneManager aware of this potential setting, the user only has to make sure NetworkObjects that have a scene dependency are marked as such (NetworkObject.SetSceneAsDependency) so the assets that a NetworkObject are dependent upon are instantiated before or with the dependent NetworkObjects.

We don't completely automate this process for the user, but we provide the option to at least assure a NetworkObject is not instantiated until a specific scene is loaded.

NetworkSceneManager only groups NetworkObjects to the scenes they are associated with or have a dependency with and will deserialize them in that order. We do not migrate NetworkObjects to scenes or the like, that is left up to the user, but we do provide a way to assure that when a NetworkObject is being deserialized it is done only after the scene it is associated with (GameObject.scene) or it is dependent upon (NetworkObject.DependentSceneName) is loaded first. What happens from there is up to the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was resolved by updating the way I approached how things are loaded.
Now we load all scenes first (not spawning or soft synchronizing during the loading), and then once all scenes are loaded we handle local spawning and soft synchronization. Made updates to the RFC to reflect these changes.

Comment on lines 94 to 96
![](0000-additivescenes-and-networkscenemanager-refactoring/NSM_Reference11.png)

In order to set a scene dependency for a NetworkObject that has a dependency in a different scene (in this case the spawn generator), the user is only required to set the scene as a dependency for the dependent NetworkObject as such:
Copy link
Contributor

Choose a reason for hiding this comment

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

here again, I'm not sure why we care about scene dependencies of networkobjects. if a developer wants to implement an object pool, put that into a separate scene, load that scene at runtime and spawn objects by that spawnpool to manage — why "netcode" needs to care about that at all? I'd say, that's something for implementor to figure out, if they have strong dependencies between objects being spawned/pooled and the spawnpool implementation. well, I think we could chat about that :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(see the previous response above)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We no longer care about scene dependencies. We now only care when certain NetworkObjects are soft synchronized or spawned, but that is only the special case of NetworkPrefabHandler related stuff. In terms of scenes and dependencies that has been addressed in the most recent update in PR-955 and is reflected in this RFC.

@JesseOlmer JesseOlmer added the open RFC is open for review and comments label Aug 13, 2021
Updated the RFC to reflect the most current updates to the NetworkSceneManager.
Weird merge bug?
minor style
Found some legacy text copy that needed to be updated to the new synchronization loading process.
Hopefully improving upon the client side process description.
Adjusted diagram for better clarity (server vs client) and some minor alignment issues.
One last area that needed adjustment since we do not provide the original scenario.
minor text copy adjustment for better clarity.
updated diagram that was too small.
@0xFA11
Copy link
Contributor

0xFA11 commented Aug 24, 2021

do you think this RFC is up-to-date and good to go by now @NoelStephensUnity ?

NoelStephensUnity and others added 5 commits October 8, 2021 16:58
Updating RFC to match the new SceneEventType enum values.
Updated both text and images.
fixing typos.
Cleaning this up to be aligned with pre-3 release.
Updating the tracking event notification description to provide context of usage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open RFC is open for review and comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants