Dynamically spawning NetworkObjects in Boss Room to resolve zombie NetworkObjects
Required reading: Object Spawning.
This document serves as a walkthrough of Boss Room's approach to solving the following issue: Late-joining clients entering networked sessions encountering zombie NetworkObjects
. Zombie NetworkObjects
represent NetworkObjects
that are instantiated for a client due to scene loads but aren't despawned or destroyed by Netcode.
This is a particular Netcode limitation of NetworkObject
spawning: NetworkObjects
that belong to a scene object should not be destroyed until its scene has been unloaded through Netcode's scene management.
The scenario in question:
- A host loads a scene and destroys a
NetworkObject
that belonged to that scene. - A client joins the host's session and loads the additive scene. This operation loads all the
GameObjects
included in the additive scene. TheNetworkObject
that was destroyed on the server won't be destroyed on the client's machine.
This scenario manifested inside Boss Room, whereby late-joining clients joining a game session encountered zombie NetworkObject
s that were not destroyed over the network.
Additive scenes now contain Prefab instances of a custom spawner, NetworkObjectSpawner
to accommodate this visual inconsistency.
Compositionally, these additive scenes now only contain the following:
- Prefab instances of level geometry.
- Prefab instances of
NetworkObject
s that will not be despawned nor destroyed for the scene's lifetime. Examples include BreakablePot and BreakableCrystal. - Prefab instances of
NetworkObjectSpawner
, which spawnNetworkObject
s that may be destroyed or despawned during the scene's lifetime. Examples include Imp, VandalImp, and ImpBoss.