Skip to content

refactor: simplify scene search loop in GetDefaultServerDiscoveryPort#364

Merged
from2001 merged 2 commits intofix/search-netsync-manager-in-all-loaded-scenesfrom
copilot/sub-pr-363
Mar 8, 2026
Merged

refactor: simplify scene search loop in GetDefaultServerDiscoveryPort#364
from2001 merged 2 commits intofix/search-netsync-manager-in-all-loaded-scenesfrom
copilot/sub-pr-363

Conversation

Copy link
Contributor

Copilot AI commented Mar 8, 2026

The for (int i = -1; ...) sentinel pattern in GetDefaultServerDiscoveryPort was hard to follow and called SceneManager.GetActiveScene() twice inside the loop body.

Changes

  • StartPythonServer.cs: Replaced the sentinel loop with an explicit ordered list:
    • Store activeScene once upfront
    • Build a List<Scene> with activeScene first, then append all other loaded scenes
    • Iterate with a straightforward foreach
// Before
for (int i = -1; i < SceneManager.sceneCount; i++)
{
    Scene scene;
    if (i == -1)
        scene = SceneManager.GetActiveScene();
    else
    {
        scene = SceneManager.GetSceneAt(i);
        if (scene == SceneManager.GetActiveScene()) continue;
    }
    ...
}

// After
Scene activeScene = SceneManager.GetActiveScene();
var scenesToSearch = new List<Scene> { activeScene };
for (int i = 0; i < SceneManager.sceneCount; i++)
{
    Scene s = SceneManager.GetSceneAt(i);
    if (s != activeScene)
        scenesToSearch.Add(s);
}
foreach (Scene scene in scenesToSearch) { ... }

Search order (active scene first) is preserved.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: from2001 <387880+from2001@users.noreply.github.com>
Copilot AI changed the title [WIP] Update search implementation for NetSyncManager based on feedback refactor: simplify scene search loop in GetDefaultServerDiscoveryPort Mar 8, 2026
@from2001 from2001 marked this pull request as ready for review March 8, 2026 08:30
@from2001 from2001 merged commit 6a2d2a8 into fix/search-netsync-manager-in-all-loaded-scenes Mar 8, 2026
from2001 added a commit that referenced this pull request Mar 8, 2026
* fix: search NetSyncManager in all loaded scenes, not just active scene

When multiple scenes are loaded, GetDefaultServerDiscoveryPort() now
searches all loaded scenes for NetSyncManager if it's not found in
the active scene.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: simplify scene search loop in GetDefaultServerDiscoveryPort (#364)

* Initial plan

* refactor: simplify GetDefaultServerDiscoveryPort scene search loop

Co-authored-by: from2001 <387880+from2001@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: from2001 <387880+from2001@users.noreply.github.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: from2001 <387880+from2001@users.noreply.github.com>
@from2001 from2001 deleted the copilot/sub-pr-363 branch March 14, 2026 11:19
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.

2 participants