What happen if a scene has been preload more than once?

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

What will happen if a scene has been preload more than once from different scripts?

Does the scene only been preload to memory the first time when a script calls, after that, since the scene is already in memory, the following calls from different scripts will just use the scene in memory.


preloading scene into memory will be executed every time when a script calls, the same scene will overwrites the already in memory one every time a script calls? Thank you!

:bust_in_silhouette: Reply From: Gluon

It depends. If you create a script with a variable which is empty and then as part of a loop, (the _process(delta) function for example) you assign a scene then it will keep overwriting the previous variable data. On the other hand if you have separate scripts with different nodes each with their own variable then you will have multiple separate variables each with their own instance of the scene in memory.

If you want to preload it only once and use it multiple times you could create a variable in a global script and autoload that each time you change scene. Then you can have a single instance in memory which can be called from any other script.

Thanks for the answer. If I have a blink effect scene that has been used by many other scenes, instead of preloading it in every individual scene that uses it. It would be more optimised to preload it only once in a global script so it would only be loaded to memory once? Thank you.

Idleman | 2022-01-08 11:35