feat: Adds nested NetworkObject support in prefabs #2645
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Allows users to spawn nested NetworkObjects in prefabs. This is done using a new dependent NetworkObjects system.
When you spawn a prefab with nested NetworkObjects, all of the nested NetworkObjects will also be spawned/synchronized. These nested NetworkObjects will be dependent on the root NetworkObject. This means they are initially synchronized in the same message as the root NetworkObject, and cannot outlive the root NetworkObject (when the root gets destroyed the depending NetworkObjects will be destroyed as well). Aside from these two exceptions, depending NetworkObjects behave identically to normal NetworkObjects.
To achieve this I made 3 major changes:
NetworkObject
for saving its dependent NetworkObject and depending NetworkObjects. Respectively, these arem_DependentNetworkObject
andm_DependingNetworkObjects
. They are determined inOnValidate
and have public getters.Spawn()
is called on a NetworkObject, it locally spawns depending NetworkObjects as well.SceneObject
struct (which contains the data needed to spawn or initially synchronize NetworkObjects) now contains a list ofDependingSceneObject
s. This is a new struct that contains a subset of the properties ofSceneObject
along with aIsSpawned
boolean. When a SceneObject is spawned remotely, the information in theDependingSceneObject
list is used to initialize the depending NetworkObjects. AnyDependingSceneObject
whereIsSpawned
is false has its corresponding NetworkObject destroyed instead of initialized. This occurs when a depending NetworkObject has been destroyed before the NetworkObject it is dependent on.Resolves #2637
Changelog
Testing and Documentation