scene-loader icon indicating copy to clipboard operation
scene-loader copied to clipboard

Request: Transition to Current Scene (Reload Current Scene)

Open miltoncandelero opened this issue 8 months ago • 3 comments

Summary

A way to transition to a copy of the current scene.

Problem or Use Case

Very useful for "restarting a level". Having a single button that no matter what level in your game you are, you can reload it and start from a fresh state.

Proposed Solution

I've achieved it previously (v3.x) by keeping track of the parameters for the last call to TransitionToScene and simply retriggering the last TransitionToScene.

There could also be a way from MySceneManager.GetActiveScene() but I can't find something that works with Addressables (I can't get the addressable back from the active Scene reference)

PS: Amazing v4 overhaul. Pretty close to my boilerplate but much more robust <3

Acknowledgement

  • [x] I have searched the existing issues to ensure this feature hasn't been requested already

miltoncandelero avatar Apr 02 '25 21:04 miltoncandelero

Hi @miltoncandelero, thank you for opening this issue.

Maybe we could have a method for that, what do you think? Now that you said it, it makes sense to have a way to easily reload scenes. It could also offer the possibility of having an intermediate scene.

I'm thinking of something along these lines:

public Task<SceneResult> ReloadActiveScene(ILoadSceneInfo intermediateScene = null, CancellationToken = default);

Does that align with your proposal?

Also, you mentioned there's no way to get the addressable back from the active scene reference. Would you like to have this possibility as well? Internally we have this information via the ISceneData implementations.

joaoborks avatar Apr 03 '25 13:04 joaoborks

I'm thinking of something along these lines:

public Task<SceneResult> ReloadActiveScene(ILoadSceneInfo intermediateScene = null, CancellationToken = default);

Does that align with your proposal?

Yeah, that's pretty much what I had in mind!

Also, you mentioned there's no way to get the addressable back from the active scene reference. Would you like to have this possibility as well? Internally we have this information via the ISceneData implementations.

I... don't think so? If we solve the reloading internally I am not sure what I could need the Addressable scene for 🤔

miltoncandelero avatar Apr 03 '25 13:04 miltoncandelero

We have a deal then. I'll implement this method and start a PR.

joaoborks avatar Apr 03 '25 13:04 joaoborks

Hey @miltoncandelero, sorry for taking so long to open the PR. Could you take a look at it to see if you spot any improvements and opportunities?

joaoborks avatar Jul 01 '25 02:07 joaoborks

I'll merge the PR but feel free to reopen the issue and request improvements if needed.

joaoborks avatar Jul 08 '25 00:07 joaoborks

:tada: This issue has been resolved in version 4.1.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

joaoborks avatar Jul 08 '25 00:07 joaoborks