Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix multiple scene loading order issues #418

Merged
merged 22 commits into from
Oct 21, 2020
Merged

Conversation

uweeby
Copy link
Member

@uweeby uweeby commented Oct 20, 2020

This PR fixes a handful of related timing issues with scene loading. I tried to break this up in other smaller PRs but this chunk is too tangled. The intent is not to change functionality or flow but instead fix bugs or oversights in the existing code.


Before: FinishLoadScene would fire before scene change actually completed
After: hook AsyncOperation.Complete to wait for completion.

Reason for change: this was the original inspiration for the change Unity Developer Forum Post. After some testing I confirmed that the UnityEvents for Post scene change were firing before the scene change completed in some scenarios. This was hidden by the IsReady code.


Before: On connect the server will only tell you the NetworkSceneName if the server had changed scene since it started.
After: On connect the server will ALWAYS tell you the NetworkSceneName (returns SceneManager.GetActiveScene().name) every time.

Reason for change: this prevent ambiguous situations where the client and server could start in different scenes.


Before: HostClient would not register any Scene related msg handlers.
After: HostClient registers Scene change msg handler.

Reason for change: this sends all scene changes through the same code paths. Eventually results in less redundant calls and host/client checks.


Before: PlayerSpawner used Authenticated to AddNewPlayerMessage.
After: PlayerSpawner uses ClientSceneChanged (Normal scene change only) to AddNewPlayerMessage.

Reason for change: The player will need to be spawned after a normal scene change happens (as its detroyed in that process since its not DDOL). There is no reason to couple that action to Authenticated as that may have unintended side effects. Also helps remove code from NetworkSceneManager as the existing event can handle this situation instead.

@uweeby uweeby added Needs testing Work In Progess Shouldn't be merged yet labels Oct 20, 2020
Copy link
Contributor

@paulpach paulpach left a comment

Choose a reason for hiding this comment

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

After: On connect the server will ALWAYS tell you the NetworkSceneName (returns SceneManager.GetActiveScene().name) every time.

Use .path instead of .name. We usually have lots of scenes with the same name in different paths.

After: PlayerSpawner uses ClientSceneChanged (Normal scene change only) to AddNewPlayerMessage.

What happens if I only have one scene for everything (like in basic example)?

Assets/Mirror/Runtime/NetworkSceneManager.cs Outdated Show resolved Hide resolved
@sonarcloud
Copy link

sonarcloud bot commented Oct 21, 2020

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 1 Code Smell

63.0% 63.0% Coverage
0.0% 0.0% Duplication

@uweeby uweeby removed Needs testing Work In Progess Shouldn't be merged yet labels Oct 21, 2020
@uweeby uweeby changed the title WIP: Fix scene loading order fix: fix multiple scene loading order issues Oct 21, 2020
@uweeby uweeby merged commit 6d8265d into master Oct 21, 2020
@uweeby uweeby deleted the fixSceneLoadingOrder branch October 21, 2020 20:34
github-actions bot pushed a commit that referenced this pull request Oct 21, 2020
## [51.1.2](v51.1.1...v51.1.2) (2020-10-21)

### Bug Fixes

* fix multiple scene loading order issues ([#418](#418)) ([6d8265d](6d8265d))
@github-actions
Copy link
Contributor

🎉 This PR is included in version 51.1.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants