Question about load() and preload()

Godot Version

4.6.1

Question

Hi I have a small question if I use preload(scene.tscn) and load a scene in a autoload script and after that if I use
load(scene.tscn) somewhere else will it load a new scene or just return a reference to it because it’s already in ram?

I didn’t find anything about this in the doc and AI gives conflicted answers
thank you

1 Like

From the documentation:

“Returns a Resource from the filesystem located at the absolute path. Unless it’s already referenced elsewhere (such as in another script or in the scene), the resource is loaded from disk on function call, which might cause a slight delay, especially when loading large scenes.”

2 Likes

Hummm ok.. so you mean preloading is better?.

OMG thanks totally missed that

1 Like

Well i use preloading this give smooth transitions to next scene because it’s preloaded so no Jerk or delays.

1 Like

preload is a compile-time operation. This means you cannot have a dynamic path there, you HAVE to include a DIRECT path to whatever it is you want to load, so if, for example, you want to preload something like this:

res://path/to/img_" + i + ".png", it will not work.

In those cases, you have to use load, which is a run-time operation.

Both are used for different purposes, it’s not a case of “X is better than Y”.

3 Likes

Ok thank bro. For information :grinning_face_with_smiling_eyes: