Skip to content

Commit 562bc8e

Browse files
author
Larah Armstrong
authored
Merge branch 'develop' into main
2 parents 5ee6560 + 855a8d2 commit 562bc8e

File tree

5 files changed

+77
-1
lines changed

5 files changed

+77
-1
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
id: networkobject-parenting
3+
title: NetworkObject Parenting inside Boss Room
4+
description: Learn about Boss Room's approach to NetworkObject parenting.
5+
---
6+
:::note
7+
Required reading: [NetworkObject Parenting](../../advanced-topics/networkobject-parenting.md)
8+
:::
9+
10+
Before detailing Boss Room’s approach toon `NetworkObject` parenting, it’s important to highlight a limitation of Netcode: A dynamically-spawned `NetworkObject` **cannot** contain another `NetworkObject` in its hierarchy. If you spawn such a `NetworkObject`, you cannot spawn children `NetworkObjects`. You can only add children `NetworkObject` components to a `NetworkObject` that is part of a scene.
11+
12+
Boss Room leverages `NetworkObject` parenting through the server-driven `PickUp` action (see [`PickUpAction.cs`](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop/blob/main/Assets/Scripts/Gameplay/Action/ConcreteActions/PickUpAction.cs)), where a character has the ability to pick up a specially-tagged, in-scene placed `NetworkObject` (see [`PickUpPot` prefab](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop/blob/main/Assets/Prefabs/Game/PickUpPot.prefab)].
13+
14+
At its root, `PickUpPot` contains a `NetworkObject`, a `NetworkTransform`, and a `PositionConstraint` component. `AutoObjectParentSync` is enabled on its `NetworkTransform` (as is by default) so that:
15+
16+
1. The `NetworkObject` can verify server-side if parenting a Heavy object to another `NetworkObject` is allowed.
17+
2. The `NetworkObject` can notify us when the parent has successfully been modified server-side.
18+
19+
To accommodate the limitation highlighted at the beginning of this document, Boss Room leverages the `PositionConstraint` component to simulate an object following a character’s position.
20+
21+
A special hand bone has been added to our Character’s avatar. Upon a character’s successful parenting attempt, this special bone is set as the `PickUpPot`’s `PositonConstraint` target. So while the `PickUpPot` is technically parented to a player, the `PositionConstraint` component allows the `PickUpPot` to follow a bone’s position, presenting the **illusion** that the `PickUpPot` is parented to the player’s hand bone itself.
22+
23+
Once the `PickUpPot` is parented, local space simulation is enabled on its [`NetworkTransform` component](../../components/networktransform.md).
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
id: networkrigidbody
3+
title: NetworkRigidbody inside Boss Room
4+
description: Learn how Boss Room leverages NetworkRigidbody.
5+
---
6+
:::note
7+
Required reading: [Physics](../..//advanced-topics/physics.md)
8+
:::
9+
10+
Boss Room leverages `NetworkRigidbody` to simulate physics-based projectiles. See the Vandal Imp’s tossed projectile, the [`ImpTossedItem` prefab](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop/blob/main/Assets/Prefabs/Game/ImpTossedItem.prefab). At its root, this prefab contains a `NetworkObject`, a `NetworkTransform`, a `Rigidbody`, and a `NetworkRigidbody` component. Refer to [`TossAction.cs`](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop/blob/main/Assets/Scripts/Gameplay/Action/ConcreteActions/TossAction.cs) for more implementation details.
11+
12+
An important note: Any modifications to a `Rigidbody` that involve Physics (that is, modifying velocity, applying forces, applying torque, and the like) must be done **after** the `NetworkObject` is spawned since `NetworkRigidbody` forces the Rigidbody’s `isKinematic` flag to be true on `Awake()`. Once spawned, this flag is modified depending on the ownership status of the `NetworkObject`.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
id: spawn-networkobjects
3+
title: Dynamically spawning NetworkObjects in Boss Room to Resolve Zombie NetworkObjects
4+
description: Learn how to dynamically spawn NetworkObjects in Boss Room to resolve zombie NetworkObjects.
5+
---
6+
:::note
7+
Required reading: [Object Spawning](../../basics/object-spawning.md).
8+
:::
9+
10+
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 are not despawned or destroyed by Netcode.
11+
12+
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.
13+
14+
The scenario in question:
15+
16+
* A host loads a scene and destroys a `NetworkObject` that belonged to that scene.
17+
* A client joins the host’s session and loads the additive scene. This operation loads **all** the `GameObjects` included in the additive scene. The `NetworkObject` that was destroyed on the server will not be destroyed on the client’s machine.
18+
19+
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.
20+
21+
Additive scenes now contain prefab instances of a custom spawner, [`NetworkObjectSpawner`](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop/blob/main/Packages/com.unity.multiplayer.samples.coop/Utilities/Net/NetworkObjectSpawner.cs) to accommodate this visual inconsistency.
22+
23+
Compositionally, these additive scenes now only contain the following:
24+
25+
* Prefab instances of level geometry.
26+
* Prefab instances of `NetworkObject`s that will **not** be despawned nor destroyed for the scene’s lifetime. Examples include [BreakablePot](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop/blob/main/Assets/Prefabs/Game/BreakablePot.prefab) and [BreakableCrystal](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop/blob/main/Assets/Prefabs/Game/BreakableCrystal.prefab).
27+
* Prefab instances of `NetworkObjectSpawner`, which spawn `NetworkObject`s that **may** be destroyed or despawned during the scene’s lifetime. Examples include [Imp](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop/blob/main/Assets/GameData/Character/Imp/Imp.asset), [VandalImp](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop/blob/main/Assets/GameData/Character/VandalImp/VandalImp.asset), and [ImpBoss](https://github.com/Unity-Technologies/com.unity.multiplayer.samples.coop/blob/main/Assets/GameData/Character/ImpBoss/ImpBoss.asset).

docs/tutorials/helloworld.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ public class NetworkCommandLine : MonoBehaviour
171171

172172
9. Paste the copied code into your code editor.
173173
1. Save your changes. Your script will reload in the Unity Editor.
174-
1. Back in the Editor, select **File** > **Build Settings** > **Player Settings...**. Beneath **Settings for PC, Mac, & Linux Standalone**, click **Resolution and Presentation** to open the section options.
174+
1. Back in the Editor, open **Edit** -> **Project Settings**
175+
1. Select the **Player tab**.
176+
1. Expand the **Resolution and Presentation**.
175177
1. From **Resolution** > **Fullscreen Mode**, change `Fullscreen Window` to `Windowed`.
176178
1. Back to the Editor main window, save your scene.
177179

sidebars.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,18 @@ module.exports = {
370370
"type": "doc",
371371
"id": "learn/bossroom/bossroom-actions"
372372
},
373+
{
374+
"type": "doc",
375+
"id": "learn/bossroom/networkobject-parenting"
376+
},
377+
{
378+
"type": "doc",
379+
"id": "learn/bossroom/networkrigidbody"
380+
},
381+
{
382+
"type": "doc",
383+
"id": "learn/bossroom/spawn-networkobjects"
384+
},
373385
],
374386
},
375387
{

0 commit comments

Comments
 (0)