Skip to content

Conversation

@noellie-velez
Copy link
Collaborator

@noellie-velez noellie-velez commented Dec 29, 2025

Purpose of this PR

Jira ticket

MTT-13657

Changelog

  • Changed: optimize NetworkManager accessors
  • Changed: styling (fixing typos and minor styling)
  • Changed: use explicit Unity engine object lifetime check

Documentation

  • No documentation changes or additions were necessary.

Testing & QA (How your changes can be verified during release Playtest)

Functional Testing

Manual testing :

  • Manual testing done

Automated tests:

  • Covered by existing automated tests
  • Covered by new automated tests

Does the change require QA team to:

  • Review automated tests?
  • Execute manual tests?
  • Provide feedback about the PR?

If any boxes above are checked the QA team will be automatically added as a PR reviewer.

Backports

@noellie-velez noellie-velez marked this pull request as ready for review December 30, 2025 14:54
@noellie-velez noellie-velez requested a review from a team as a code owner December 30, 2025 14:54
// Only dynamically spawned NetworkObjects that are not already in the newly assigned active scene will migrate
// and update their scene handles
if (IsSceneObject.HasValue && !IsSceneObject.Value && gameObject.scene != next && gameObject.transform.parent == null)
if (IsSceneObject.HasValue && !IsSceneObject.Value && m_SceneOrigin != next && m_CachedParent == null)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_SceneOrigin is the actual one or the starting one (is a ref or a copy)

This comment was marked as resolved.

Copy link
Collaborator Author

@noellie-velez noellie-velez Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But are they for transform.parent just bellow?

// Only dynamically spawned NetworkObjects that are not already in the newly assigned active scene will migrate
// and update their scene handles
if (IsSceneObject.HasValue && !IsSceneObject.Value && gameObject.scene != next && gameObject.transform.parent == null)
if (IsSceneObject.HasValue && !IsSceneObject.Value && m_SceneOrigin != next && m_CachedParent == null)

This comment was marked as resolved.

@noellie-velez noellie-velez force-pushed the chore/simplify-accessors-network-object branch from 02d061d to aab3f4d Compare January 9, 2026 18:43
Copy link
Member

@EmandM EmandM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really good!

// Early exit if the NetworkManager is shutting down, the NetworkObject
// is not spawned, or an in-scene placed NetworkObject
if (NetworkManager == null || NetworkManager.ShutdownInProgress || !IsSpawned || IsSceneObject != false)
if (!IsSpawned || IsSceneObject != false || NetworkManager.ShutdownInProgress)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsSceneObject is a bool? type which means the value can be null | true | false so this check needs to return true when the value is null | true but false when the value is false.

That is to say, this check here is already a contraction of (IsSceneObject == null || IsSceneObject.HasValue). Unfortunately we can't contract it further.

}

// Do the safety loop first to prevent putting the netcode in an invalid state.
for (int i = 0; i < networkObjects.Count; i++)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun fact, we can remove this whole loop, as all these checks should be done in the underlying function.

I think the most important next task for you is to pull out these exceptions!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should address this comment in another PR, right? I mean, I should not remove the loop until I pull out these exceptions, right?

Copy link
Collaborator Author

@noellie-velez noellie-velez Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing the following comment I guess I should remove both loops and pull out the exceptions on a next PR.Let me know if that's not what you meant to put it back in.

}

// Do the safety loop first to prevent putting the netcode in an invalid state.
for (int i = 0; i < networkObjects.Count; i++)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here, just remove this whole pre-process loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants