Is it a good idea to ResourceLoader.Load() at the top of the script? (C#)

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

Hi!

I’ve been doing this for quite a while now, simply because it makes my code so much cleaner and easy to read, but I’m not quite sure if this is a bad practice. I started doing this because I saw some code written in gdscript which used preload(), which isn’t a thing in C#.

Does using ResourceLoader.Load() at the top of the script to declare a PackedScene variable affect in a negative way the performance of my game?

Here is an example code in C#:
PackedScene chicken = (PackedScene)ResourceLoader.Load("res://Assets/Scenes/Animals/Chicken.tscn");

Thanks in advance!

:bust_in_silhouette: Reply From: juppi

Hi!

No, unless you do it once at when the game starts or scene switches.

ResourceLoader.Load is an I/O operation, which loads content from disk. So just don’t put it into the Process(float delta) method.