How can we best reload or restart the current Scene?

Hello! I’m looking for a way to restart everything in a scene when it reaches the end. In Unity I’d do that by simply calling “LoadScene” and give it the current scene’s index, and I took a look at the SceneSwitcher sample to try the same approach, but it doesn’t look like the SceneSwitcher script supports this just yet. In a pinch, I can just refresh the page… but is there a better way?

Original Post on Discord

by user 248501710404845568

I think you could unassign and re-assign the needle-engine src to dispose and recreate everything which might or might not be expensive depending on your scene complexity (and I think you have quite some heavy models that take a moment to be setup, not even the loading part but building the scene)

The SceneSwitcher could be used for that on a sub-scene level altough it doesnt have a method for “reload” (and it doesnt load the same scene again if you call with the same name or index) - it would result in the same thing tho - the subscene objects would all be re-created which would not be ideal.

If you ask for the project I’m thinking about then I would rather keep track of the relevant state in a script of yours that does the resetting to avoid rebuilding the whole scene.

that sounds wise, thanks!! either of these approaches sounds much better than just a page refresh, so we’ll probably give the dispose-and-recreate approach a try, and then settle for a (riskier?) state approach if that doesn’t meet our needs. All set for now, then!

by user 248501710404845568