Loading prefabs via resources.load vs. member-variables

So I’ve a lot of prefabs that I load as needed via Resources.Load. Furthermore, I also have an insane amount of memory being used on-load.

The scripting guide gives the following guidance on how to deal with loading in resources:

My question is, for pulling in a lot of prefabs as needed is it better (memory-usage and load-speed wise) to use Resources.Load, or is it better to assign a variable in a script with each and every prefab and reference that variable as needed?

In either case the number of prefabs would be the same – in other words, there are no extraneous prefabs kept in the Resources folder that I don’t potentially need to use, so would not storing objects in the Resources folder really make a difference if they’re just going to get pulled in via the variables?

Thanks!

The significance of variable links versus Resources.Load is more to do with development than anything else. A complicated project can often end up with unused assets, or assets that are only used in specific versions of the game (say if you have a free and a paid version of the same game). Using links in the inspector, Unity can determine which assets are actually used by the game and which are just hanging around in the project. There isn’t any way to decide whether something in the Resources folder will be used or not, so Unity just has to copy the whole contents of the folder to the finished build.

If you use Resources.Load, but are careful to weed out any unused assets before the build, then you won’t see much difference. The inspector link system is intended to save you this manual task.

if you load them, they will always be equally heavy on both sides.

if you though can restrict the amount of loaded data, resource load / instantiate will get you further, but it also means more programming work

1 Like

That’s what I thought. Thanks, guys.

I’m still trying to hunt down what’s actually causing my memory to balloon out, but apparently it’s not the prefabs. Taking them completely out of the picture and doing a build without them doesn’t decrease the memory footprint by that much, so the hunt continues!