0 votes

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!

Godot version v3.4
in Engine by (266 points)

1 Answer

+1 vote

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.

by (2,155 points)

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.