Resource.Load v Inspector object reference

How does Unity work under the hood, and which of these is 1. faster, and 2. lower in resource use?

The first is to use Resource.Load every time I want to grab a prefab, texture, etc.

The second is to have a Monobehaviour on a GameObject that I can drag/drop prefabs, textures, and the like in to the inspector fields as a reference.

Is Unity loading these references into memory behind the scenes, or just when needed. What’s going on?

1 Answer

1

Generally speaking it’s faster to use references. However loading things yourself with resources or streamingassets gives you a lot more flexibility. For instance if you want to support both high and low resolutions you’ll need to wait until the program is launched to figure out whether to use a high res or low res image.

As a general rule only use resources when you have no other choice.

So the best thing to do would be to create a new GameObject in the hierarchy and attach a script that has all the references in it. Rather than loading everything with resources.load at the start of the scene?

yes, until you need logic to decide which asset to use.

So, does using references actually keep the referenced items in memory, so there's no loading - or does it just make that loading quicker?

It doesn't keep them in memory. Where the run time efficiency comes in is not having to search the resources folder to find the appropriate asset. There are also efficiencies to work flow and file size.