Will reloading the scene cause performance issues?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By HatEm
:warning: Old Version Published before Godot 3 was released.

My game is kind of arcadey so the player will respawn a lot will that cause performance issues if I use get_tree().change_scene(“res://current_level”) to respawn?

The scene is not too large but kinda large all collision objects are Area except 10 StaticBodies and a RigidBody which is the player himself

HatEm | 2016-12-16 22:28

I’ve tested it in the current Level it works awesomely fine and smooth but I’m planning on making larger levels, will change_scene() affect the performance?

HatEm | 2016-12-16 23:22

:bust_in_silhouette: Reply From: Zylann

It’s Ok to use change_scene() (or, in more general terms, destroy and recreate a set of nodes).

I mainly see two ways of respawning:

  1. Destroy everything, re-create everything. Safest and simplest option, it works best when the level is also complex and you don’t need to remember anything that was in there. It can become slower if your scene is big, but Godot loads scenes pretty fast depending on which nodes they contain. using a thread + a fullscreen animation can make it smoother if a short freeze is noticeable.

  2. Reset only the things that needs to and leave the rest untouched. Can be extremely fast because it involves little to no construction or memory allocations, but requires a bit more setup and caution. Works best when there are not much things that need a reset, but can be still worth it depending on the game.

I use 2) in my game because not much stuff change, it’s fast and I need to keep some nodes alive instead of re-creating them. I created a “respawners” group that will receive a call_group message when the level restarts so they can reset themselves. But it’s easier to make mistakes when doing that, hence the word “caution”.

If you use 1) and you don’t notice a performance issue, then fine, continue using it :slight_smile:
If you are using .tscn, Godot even converts it to .scn (binary) when the game is exported in addition to removing debug overhead, so loading is always faster.
I would suggest you use the best solution for your usage first, but if you encounter a performance issue, and only then, start optimizing, by using either 2) or a mix between the two.

In the most extreme case (huge bigass scenes), you would have to defer the loading of some parts of your scene, or chunk it in parts that can be loaded one after the other as they are needed.

The scene is not too large but kinda large

Hmm you could provide some numbers here, all is relative^^

Your right, I forgot about that when you export the game it runs faster, 1 works fine for me while debugging I didn’t face big performance issues (I little ones but optimized the scene with VisibilityNotifier) and I think when I export the game it will run smooth, also I freeze the player at the start, more clearly at _ready(), and when I reload the scene _ready() gets called and freezes the player each time and that’s an awesome feature created by accident

HatEm | 2016-12-18 16:30

And After looking at my scene again I exaggerated when I said “it’s not large but kinda large”, it’s small tbh

HatEm | 2016-12-18 16:33