Skip to content

Commit b255749

Browse files
committed
Use m_CachedParent and Scene
1 parent 7d9ffd5 commit b255749

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,17 +334,17 @@ private void CheckForInScenePlaced()
334334

335335
internal bool HasParentNetworkObject(Transform transform)
336336
{
337-
if (transform.parent != null)
337+
if (m_CachedParent != null)
338338
{
339-
var networkObject = transform.parent.GetComponent<NetworkObject>();
339+
var networkObject = m_CachedParent.GetComponent<NetworkObject>();
340340
if (networkObject != null && networkObject != this)
341341
{
342342
return true;
343343
}
344344

345-
if (transform.parent.parent != null)
345+
if (m_CachedParent.parent != null)
346346
{
347-
return HasParentNetworkObject(transform.parent);
347+
return HasParentNetworkObject(m_CachedParent);
348348
}
349349
}
350350
return false;
@@ -3427,7 +3427,7 @@ private void CurrentlyActiveSceneChanged(Scene current, Scene next)
34273427
{
34283428
// Only dynamically spawned NetworkObjects that are not already in the newly assigned active scene will migrate
34293429
// and update their scene handles
3430-
if (IsSceneObject.HasValue && !IsSceneObject.Value && gameObject.scene != next && gameObject.transform.parent == null)
3430+
if (IsSceneObject.HasValue && !IsSceneObject.Value && m_SceneOrigin != next && m_CachedParent == null)
34313431
{
34323432
SceneManager.MoveGameObjectToScene(gameObject, next);
34333433
SceneChangedUpdate(next);
@@ -3486,7 +3486,7 @@ internal void SceneChangedUpdate(Scene scene, bool notify = false)
34863486
OnMigratedToNewScene?.Invoke();
34873487

34883488
// Only the authority side will notify clients of non-parented NetworkObject scene changes
3489-
if (isAuthority && notify && transform.parent == null)
3489+
if (isAuthority && notify && !m_CachedParent)
34903490
{
34913491
NetworkManager.SceneManager.NotifyNetworkObjectSceneChanged(this);
34923492
}

0 commit comments

Comments
 (0)