Optimize scene reloading

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Afely

Whenever I reload the current scene, my game gets a somewhat big lag spike. That wouldn’t be too big a deal, except it’s a pretty difficult game, so if there was a lag spike every time you reset the level it would get annoying quick. I’m not really sure how I would go about optimizing this, so any ideas are appreciated.

Update: I’ve found a way to “soft reset”, as Lopy suggested. For a while I was stumped on how to do it, but it’s actually pretty simple. Just make a group for the things that need to be reset, add functions to make them reset however you need, and then use get_tree().call_group(). Really simple, actually. I just forgot groups existed for a while, haha

:bust_in_silhouette: Reply From: Lopy

You could make a “soft” reload. Instead of reloading everything, you just replace the things that need to. Spikes regrow on ceilings, clouds teleport back to the starting lines, etc.
It can be difficult to make everything resetable, especially if you didn’t account for it and you are quite far in development, but it might be necessary if reloading everything from scratch is too slow.

Also, remember that Godot comes with a profiler. You can use it see what function take the most time

:bust_in_silhouette: Reply From: Bot7

you can make a colorrect which change visiblity.I use this too in my games. I dont know if you know what I mean. Her is a tutorial https://www.youtube.com/watch?v=_4_DVbZwmYc