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

TransitionToScene (and variants) only unload the current active scene. #45

Closed
Clozent opened this issue Aug 25, 2024 · 4 comments · Fixed by #46
Closed

TransitionToScene (and variants) only unload the current active scene. #45

Clozent opened this issue Aug 25, 2024 · 4 comments · Fixed by #46
Assignees
Labels
enhancement New feature or request

Comments

@Clozent
Copy link

Clozent commented Aug 25, 2024

When using TransitionToSceneAsync() to transition between scenes, I expected that the scene loader would unload all scenes under it's management when transitioning. Instead, no scene was unloaded at all, because I didn't make the scene I wished to unload the active scene.

This is a problem.

Unloading only the active scene is extremely limiting, as there is currently no way to transition from:

  1. A scene that is not the active scene
  2. A collection of scenes

What I propose is that ISceneLoader.TransitionToScene() and ISceneLoader.TransitionToScenes() would accept a scene or an array of scenes to unload, and that the implementations of these methods in SceneLoaderAsync, SceneLoaderCoroutine, and SceneLoaderUniTask would unload all managed scenes by default.

I know this will break backwards compatibility, but it doesn't seem like much of a problem, seeing as this package already broke some backwards compatibility in the past.

@joaoborks
Copy link
Member

Hi @Clozent, thanks for your report.

I agree with you, simply unloading the active scene only covers a simple use case. It does not need to break compatibility though, we can just add new method alternatives for scene transition, such as:

  1. Passing scenes to be unloaded
void TransitionToScenesAsync(ILoadSceneInfo[] targetScenes, int setIndexActive, ILoadSceneInfo[] unloadScenes, ILoadSceneInfo intermediateSceneReference = null)
  1. Option to unload all managed scenes
void TransitionToScenesAsync(ILoadSceneInfo[] targetScenes, int setIndexActive, bool unloadAllScenes, ILoadSceneInfo intermediateSceneReference = null)

With the new methods, you'd have three options for transition:

  1. Transition and unload the active scene (current implementation)
  2. Transition and unload a group of scenes
  3. Transition and unload all other managed scenes

What do you think? If you agree, I'll start working on it right away.

@joaoborks joaoborks self-assigned this Aug 26, 2024
@joaoborks joaoborks added the enhancement New feature or request label Aug 26, 2024
@Clozent
Copy link
Author

Clozent commented Aug 26, 2024

Hi, overall, I think these new methods are a good way to solve this problem.

One thing is bugging me, though: the method void TransitionToScenesAsync(ILoadSceneInfo[] targetScenes, int setIndexActive, bool unloadAllScenes, ILoadSceneInfo intermediateSceneReference = null) changes it's behavior depending on a boolean (unloadAllScenes, in this case), which is, from my understanding, something a method should avoid.

Instead, I think it would be best to make the behavior a separate method, such as TransitionToScenesUnloadAll(...) (I don't think this is a good name for it, but I can't come up with anything better).

@joaoborks
Copy link
Member

You're right, it'd be better to introduce a new method for unloading all scenes.

So to summarize, two new methods will be added:

  1. TransitionToScenesFromScenes - unloads multiple provided scenes
  2. TransitionToScenesFromAll - unloads all managed scenes

Not so sure about the names yet, but that's the scope. I'll start working on it today.

@joaoborks
Copy link
Member

Adding a development note for my future self:

Check whether including #44 improves the experience when using TransitionToScenesFromScenes.

@joaoborks joaoborks linked a pull request Aug 26, 2024 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants