Skip to content

Commit 18f5a10

Browse files
committed
fix: Reset cached parent when AutoObjectParentSync is false.
1 parent 67e3e1c commit 18f5a10

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,11 +2368,22 @@ internal bool InternalTrySetParent(NetworkObject parent, bool worldPositionStays
23682368
private void OnTransformParentChanged()
23692369
{
23702370
var networkManager = NetworkManager;
2371-
if (!AutoObjectParentSync || (networkManager != null && networkManager.ShutdownInProgress))
2371+
if (networkManager != null && networkManager.ShutdownInProgress)
23722372
{
23732373
return;
23742374
}
23752375

2376+
if (!AutoObjectParentSync)
2377+
{
2378+
// If this setting is off, we shouldn't be tracking parenting changes
2379+
// Ensure any tracking we do have is cleared.
2380+
if (m_CachedParent != null)
2381+
{
2382+
SetCachedParent(null);
2383+
}
2384+
return;
2385+
}
2386+
23762387
if (transform.parent == m_CachedParent)
23772388
{
23782389
return;
@@ -2388,7 +2399,6 @@ private void OnTransformParentChanged()
23882399

23892400
if (!IsSpawned)
23902401
{
2391-
AuthorityAppliedParenting = false;
23922402
// and we are removing the parent, then go ahead and allow parenting to occur
23932403
if (transform.parent == null)
23942404
{
@@ -2398,6 +2408,7 @@ private void OnTransformParentChanged()
23982408
}
23992409
else
24002410
{
2411+
AuthorityAppliedParenting = false;
24012412
transform.parent = m_CachedParent;
24022413
if (networkManager.LogLevel <= LogLevel.Error)
24032414
{

0 commit comments

Comments
 (0)