-
Notifications
You must be signed in to change notification settings - Fork 437
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
feat: Adds nested NetworkObject support in prefabs #2645
base: develop
Are you sure you want to change the base?
feat: Adds nested NetworkObject support in prefabs #2645
Conversation
Introduces the concept of Dependent NetworkObjects. Dependent NetworkObjects cannot outlive the NetworkObject they are dependent on. When spawning a prefab with nested NetworkObjects, all nested NetworkObjects are dependent on the root NetworkObject. This means that nested NetworkObjects can always be spawned/synchronized by spawning the root NetworkObject (and despawning any NetworkObjects that are no longer spawned). Resolves Unity-Technologies#2637
PR has been updated to fix a number of issues and to add tests |
Any update on this? The PR is not merged |
Still waiting after almost a year :( |
I need this too. This is the only feature that is making it impossible for me to use Netcode for GameObjects properly. Please make this happen! |
Any updates on merging this PR and getting it ported to 2.0.0? Would make my life easier |
@NoelStephensUnity Is this a feature that you/Unity would be interested in? I'd be more than happy to update my PR for the latest version if it is. |
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