Script refrence to mesh in resources folder causes mesh to be loaded into memory at start

I recently came across something that is occurring in Unity which I’m not sure why it would be happening.

If you create an item in the Resources folder, and then create a script with a reference to the item in the resources folder, then the mesh is automatically loaded into memory when starting the game. The items have never yet been “Instantiated” into the game, but yet they exist in memory when analyzing the profiler.

So here is a script with a reference to the item in the Resources folder

In the profiler, the mesh for this is loaded into memory.

No item has yet been Instantiated or created from this yet.

I am 100% positive the item does not exist in the scene and yet not been instantiated.
Is this expected to occur?
Thanks,
j
I am using Unity 5.2.3.

Well, the reference HAS to point to something, doesn’t it?

I believe you would see the same thing, regardless what folder your item is in. This reference you created via inspector has to point to something, I guess the engine does instantiate the prefab object, before giving it’s references to the scripts that need it.

I expected just a reference to exist for the Gamobject with a transform. I thought you needed to call Instantiate to actually generate the gameobject in the scene with all of the components in the prefab.

It would be nice if Unity could create some type of a serializable resources pointer type.
You could drag the prefab to this item in the script, but only it is not a gameObject but some pointer to a location in the resources. It’s really just some object which keeps track of the path to the items in the resources folder. No more need to hardcode the paths in the code.

The item wouldn’t exist until you actually told Unity to load the prefab from the pointer. I’m sure it’s possible.
All I’m trying to do is maintain a link to an item in resources folder, and then allocate the memory for it when it is required to be instantiated into the scene, not as soon as the game is started.

Edit: I found this free asset on the asset store which seems to solve this issue:

Unity is planning to phase out the resources folder and transition it to assetbundles. Then there would be no way to reference the asset anyway.

Have you checked if it is loaded in a build as well? Editor memory isn’t exactly accurate.

I haven’t checked it for a build yet. But are you saying that this might not happen in a build, but only in the editor?
I can understand now why the way this works might be expected. Sometimes you want to instantiate items in the scene very quickly, like bullets or particle systems. Then it makes sense to have the entire prefab in memory, so you don’t have to wait for stuff to be loaded from disk.
For my situation I just have to drop the reference to the prefab and switch to using Resources.Load(…).

Possibly. It may very well be intended behaviour, but it may also be an editor thing: Docs say:

http://docs.unity3d.com/Manual/ProfilerMemory.html

Your own screenshot:

2656768--187306--prefabss2.jpg