Skip to content

Commit 27af42c

Browse files
unsubscribing to a callback, comments
1 parent 156da43 commit 27af42c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Assets/BossRoom/Scripts/Shared/Game/Entity/CustomParentingHandler.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33

44
namespace Unity.Multiplayer.Samples.BossRoom
55
{
6+
/// <summary>
7+
/// This class temporarily allows NetworkObjects to be parented to children of NetworkObjects, since Netcode for
8+
/// GameObjects currently expects NetworkObjects to be parented to other NetworkObjects.
9+
/// <remarks>
10+
/// To enable a NetworkObject to be parented to this NetworkBehaviour, make sure its "Auto Object Parent Sync"
11+
/// field is toggled off.
12+
/// </remarks>
13+
/// </summary>
614
public class CustomParentingHandler : NetworkBehaviour
715
{
816
public bool preserveWorldSpace = true;
@@ -20,6 +28,11 @@ public override void OnNetworkSpawn()
2028
base.OnNetworkSpawn();
2129
}
2230

31+
public override void OnNetworkDespawn()
32+
{
33+
m_NetworkObjectChildren.OnListChanged -= NetworkObjectChildrenOnListChanged;
34+
}
35+
2336
void NetworkObjectChildrenOnListChanged(NetworkListEvent<ulong> changeEvent)
2437
{
2538
switch (changeEvent.Type)

0 commit comments

Comments
 (0)