Resources Folder - Quick Question [Resolved]

I have moved all of my game’s prefabs into the Resources folder. For maximum performance, should I move the textures and models that those prefabs reference into the Resources folder as well? I will be moving to AssetBundles/Addressables in the future, but I want to make sure I’m using the Resources folder correctly for now

Thanks.

Anything located under Resources is unconditionally included in the build output.

This also includes everything those items refer to, which is called a “dependency tree.”

There is ZERO performance difference.

The only point of Resources is for when it is not appropriate to drag things into your game scenes.

It allows you to later load those things by name using Resources.Load(), generally considered an advanced operation only necessary with specific design constructs.

If you don’t know why you are putting stuff in Resources, don’t.

Or do… it is your project after all. :slight_smile:

But understand when you do, Unity will include EVERYTHING beneath that folder, or linked by anything beneath that folder, and then your game binary will get massive, whether or not it even uses any of the stuff you threw in that folder.

There are hard limits to how much size you can put in the iOS and Android stores, plus bigger just takes more time, which is definitely an adverse performance impact.

1 Like

Thanks for the reply,

Well, I used to reference prefabs in the inspector, but my game size has gotten large, and the scenes were taking longer and longer to load. When I moved the prefabs into the Resources folder, scenes started to load lightning quick. So there was some performance gain in that regard. I was wondering if there are further gains to be had if the models and textures used in those prefabs were moved to the resources folder as well

Oh, I understand. There are definitely no unused assets in my Resources folder. I was careful to ensure that everything in there is guaranteed to be used.

It sounds more likely that you’ve just moved around when you are taking the performance hit. In a Unity scene, when you load the scene, everything referenced anywhere in the scene is loaded from disk into memory. That includes everything directly referenced, everything those things referenced, etc, etc.

You say you used to reference prefabs in the inspector. That implies that you no longer are, and are probably using Resources.Load I’m guessing. So in that case you reference less in the scene, so the scene loads faster. When you call Resources.Load in the middle of the scene, that is when you get the performance hit.

I believe when you call Resources.Load that it also loads everything referenced by that prefab, so I wouldn’t expect a difference performance wise by moving textures there. Everything in a Resources folder gets bundled together, so I’m wondering how assets not referenced in any scene, not in a Resources folder, but referenced by something in a Resources folder, end up in the build in the end if they aren’t moved to a Resources folder as well. I’d test this in a build instead of the Editor. But I don’t use Resources.Load much, so maybe it is a non-issue.

2 Likes

Thanks so much for the replies guys, much appreciated :slight_smile:

Only ~20 of the 1000+ prefabs are in use at any given time. I also have it load the prefabs from Resources asynchronously in the background, and they appear in the scene when they are ready (usually <1 second) … so thankfully there is no lag from calling Resources.Load

Yeah, that’s what I’m wondering … there are 1000+ ‘items’ that the player can acquire, and each one has a prefab associated with it (textured 3d model with colliders and such). I’ve moved the prefab into the Resources folder, but not the 3D model or texture. The 3D models and textures are not referenced anywhere by any scene (in the inspector) … they are only referenced by the prefabs in the Resources folder

Only needing 20 but were referencing 1000… That certainly sounds like a use case for Resources.Load :stuck_out_tongue:

As far as wondering, make a build, run the build, see if all your textures and whatnot are showing up properly. If they are I wouldn’t worry about it.

There isn’t anything inherently performance improving by having files located in the Resources folder. It just gives you more control on when they are loaded, rather than all at once during scene load. But you’ll be loading all the referenced textures and other assets when you Resource.Load the prefab, so I don’t see any further gains possible as long as it is working properly.

1 Like

I guess that answers my question, thanks! :slight_smile: No more performance gains eh …

Everything works properly. I just wanted to double check that it’s not making duplicates of the Assets (bloating the exported project) since the prefab is in Resources and the Textures+Models are in Assets/models.

1 Like

Pretty sure Unity is immune to this. Everything gets turned into a GUID-addressed database, so if something is included, it will never be included twice unless you physically put it in the project twice, which would give it two GUIDs. This is reasonable sometimes if you have a texture you want imported two different ways, in which case it is the only way to accomplish this.

All your game files look like this:

6878039--803321--Screen Shot 2021-02-25 at 12.23.30 PM.png

Things under Resources are there too, but they just have an extra index of their names to find them.

Otherwise, generally filenames don’t go out to the customer, except as those in Resources, AFAIK

2 Likes

With 1000 different assets, you can just verify that yourself simply with the resulting build size :stuck_out_tongue:

That’s interesting. Thanks for the in-depth response!
That resolves my question completely now

1 Like