-
Notifications
You must be signed in to change notification settings - Fork 461
fix: NetworkSceneManager clearing scene placed NetworkObjects list when ClientSynchronizationMode is additive #2383
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
Merged
NoelStephensUnity
merged 32 commits into
develop
from
fix/clientsynchronizationmode-failure-activescene-changes
Mar 2, 2023
Merged
Changes from 4 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
124c2b1
fix
NoelStephensUnity b5f8459
update
NoelStephensUnity 673d753
fix
NoelStephensUnity 5532515
test
NoelStephensUnity 27c601a
Update com.unity.netcode.gameobjects/CHANGELOG.md
NoelStephensUnity 22c5d6d
update
NoelStephensUnity 5fc02fa
Merge branch 'develop' into fix/clientsynchronizationmode-failure-act…
NoelStephensUnity f5e112c
Merge branch 'develop' into fix/clientsynchronizationmode-failure-act…
NoelStephensUnity f20cf08
update
NoelStephensUnity 5c1d1a2
Merge branch 'develop' into fix/clientsynchronizationmode-failure-act…
NoelStephensUnity fbed872
update
NoelStephensUnity f709d76
update
NoelStephensUnity dcf19f5
style
NoelStephensUnity 14287f8
revert
NoelStephensUnity ce39f8d
update
NoelStephensUnity cb391eb
update
NoelStephensUnity 364b094
test
NoelStephensUnity 189214d
update
NoelStephensUnity d793587
update
NoelStephensUnity 79fbe81
update
NoelStephensUnity 1ff5380
test and fix
NoelStephensUnity ca15b80
update and test
NoelStephensUnity 9973752
style
NoelStephensUnity 31d23e5
fix
NoelStephensUnity 6f5612b
Merge branch 'develop' into fix/clientsynchronizationmode-failure-act…
NoelStephensUnity db0a075
Merge branch 'develop' into fix/clientsynchronizationmode-failure-act…
NoelStephensUnity 8d372e6
changelog fix
NoelStephensUnity c39e0f7
update
NoelStephensUnity 18a3f38
Merge branch 'develop' into fix/clientsynchronizationmode-failure-act…
NoelStephensUnity dcd5053
Merge branch 'develop' into fix/clientsynchronizationmode-failure-act…
NoelStephensUnity 3aee658
update and fix
NoelStephensUnity 0ee065b
test
NoelStephensUnity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
com.unity.netcode.gameobjects/Runtime/SceneManagement/DefaultSceneManagerHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
| using UnityEngine.SceneManagement; | ||
|
|
||
|
|
||
| namespace Unity.Netcode | ||
| { | ||
| /// <summary> | ||
| /// The default SceneManagerHandler that interfaces between the SceneManager and NetworkSceneManager | ||
| /// </summary> | ||
| internal class DefaultSceneManagerHandler : ISceneManagerHandler | ||
| { | ||
| private Scene m_InvalidScene = new Scene(); | ||
|
|
||
| internal struct SceneEntry | ||
| { | ||
| public bool IsAssigned; | ||
| public Scene Scene; | ||
| } | ||
|
|
||
| internal Dictionary<string, Dictionary<int, SceneEntry>> SceneNameToSceneHandles = new Dictionary<string, Dictionary<int, SceneEntry>>(); | ||
|
|
||
| public AsyncOperation LoadSceneAsync(string sceneName, LoadSceneMode loadSceneMode, SceneEventProgress sceneEventProgress) | ||
| { | ||
| var operation = SceneManager.LoadSceneAsync(sceneName, loadSceneMode); | ||
| sceneEventProgress.SetAsyncOperation(operation); | ||
| return operation; | ||
| } | ||
|
|
||
| public AsyncOperation UnloadSceneAsync(Scene scene, SceneEventProgress sceneEventProgress) | ||
| { | ||
| var operation = SceneManager.UnloadSceneAsync(scene); | ||
| sceneEventProgress.SetAsyncOperation(operation); | ||
| return operation; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Resets scene tracking | ||
| /// </summary> | ||
| public void ClearSceneTracking(NetworkManager networkManager) | ||
| { | ||
| SceneNameToSceneHandles.Clear(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Stops tracking a specific scene | ||
| /// </summary> | ||
| public void StopTrackingScene(int handle, string name, NetworkManager networkManager) | ||
| { | ||
| if (SceneNameToSceneHandles.ContainsKey(name)) | ||
| { | ||
| if (SceneNameToSceneHandles[name].ContainsKey(handle)) | ||
| { | ||
| SceneNameToSceneHandles[name].Remove(handle); | ||
| if (SceneNameToSceneHandles[name].Count == 0) | ||
| { | ||
| SceneNameToSceneHandles.Remove(name); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Starts tracking a specific scene | ||
| /// </summary> | ||
| public void StartTrackingScene(Scene scene, bool assigned, NetworkManager networkManager) | ||
| { | ||
| if (!SceneNameToSceneHandles.ContainsKey(scene.name)) | ||
| { | ||
| SceneNameToSceneHandles.Add(scene.name, new Dictionary<int, SceneEntry>()); | ||
| } | ||
|
|
||
| if (!SceneNameToSceneHandles[scene.name].ContainsKey(scene.handle)) | ||
| { | ||
| var sceneEntry = new SceneEntry() | ||
| { | ||
| IsAssigned = true, | ||
| Scene = scene | ||
| }; | ||
| SceneNameToSceneHandles[scene.name].Add(scene.handle, sceneEntry); | ||
| } | ||
| else | ||
| { | ||
| throw new Exception($"[Duplicate Handle] Scene {scene.name} already has scene handle {scene.handle} registered!"); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Determines if there is an existing scene loaded that matches the scene name but has not been assigned | ||
| /// </summary> | ||
| public bool DoesSceneHaveUnassignedEntry(string sceneName, NetworkManager networkManager) | ||
| { | ||
| if (SceneNameToSceneHandles.ContainsKey(sceneName)) | ||
| { | ||
| foreach (var sceneHandleEntry in SceneNameToSceneHandles[sceneName]) | ||
| { | ||
| if (!sceneHandleEntry.Value.IsAssigned) | ||
| { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// This will find any scene entry that hasn't been used/assigned, set the entry to assigned, and | ||
| /// return the associated scene. If none are found it returns an invalid scene. | ||
| /// </summary> | ||
| public Scene GetSceneFromLoadedScenes(string sceneName, NetworkManager networkManager) | ||
| { | ||
| if (SceneNameToSceneHandles.ContainsKey(sceneName)) | ||
| { | ||
| foreach (var sceneHandleEntry in SceneNameToSceneHandles[sceneName]) | ||
| { | ||
| if (!sceneHandleEntry.Value.IsAssigned) | ||
| { | ||
| var sceneEntry = sceneHandleEntry.Value; | ||
| sceneEntry.IsAssigned = true; | ||
| SceneNameToSceneHandles[sceneName][sceneHandleEntry.Key] = sceneEntry; | ||
| return sceneEntry.Scene; | ||
| } | ||
| } | ||
| } | ||
| // If we found nothing return an invalid scene | ||
| return m_InvalidScene; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Only invoked is client synchronization is additive, this will generate the scene tracking table | ||
| /// in order to re-use the same scenes the server is synchronizing instead of having to unload the | ||
| /// scenes and reload them when synchronizing (i.e. client disconnects due to external reason, the | ||
| /// same application instance is still running, the same scenes are still loaded on the client, and | ||
| /// upon reconnecting the client doesn't have to unload the scenes and then reload them) | ||
| /// </summary> | ||
| public void PopulateLoadedScenes(ref Dictionary<int, Scene> scenesLoaded, NetworkManager networkManager) | ||
| { | ||
| SceneNameToSceneHandles.Clear(); | ||
| var sceneCount = SceneManager.sceneCount; | ||
| for (int i = 0; i < sceneCount; i++) | ||
| { | ||
| var scene = SceneManager.GetSceneAt(i); | ||
| if (!SceneNameToSceneHandles.ContainsKey(scene.name)) | ||
| { | ||
| SceneNameToSceneHandles.Add(scene.name, new Dictionary<int, SceneEntry>()); | ||
| } | ||
|
|
||
| if (!SceneNameToSceneHandles[scene.name].ContainsKey(scene.handle)) | ||
| { | ||
| var sceneEntry = new SceneEntry() | ||
| { | ||
| IsAssigned = false, | ||
| Scene = scene | ||
| }; | ||
| SceneNameToSceneHandles[scene.name].Add(scene.handle, sceneEntry); | ||
| if (!scenesLoaded.ContainsKey(scene.handle)) | ||
| { | ||
| scenesLoaded.Add(scene.handle, scene); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| throw new Exception($"[Duplicate Handle] Scene {scene.name} already has scene handle {scene.handle} registered!"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
com.unity.netcode.gameobjects/Runtime/SceneManagement/DefaultSceneManagerHandler.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.