- Home /
Resources.Load() Asset Management
I understand that Resources.Load() will get the asset at the specified path from the Resources folder. What I can't quite figure out from the documentation is the effect of calling this multiple times. Calling Resources.UnloadUnusedAssets() or Resources.UnloadAsset() can free up the memory used from loading an asset.
MyPrefab is not loaded into memory, it is only stored in the executable file
GameObject gameObj1 = Instantiate(Resources.Load("MyPrefab")) as GameObject;
Resources.Load() loads MyPrefab into memory as an asset that can be used. Instantiate() instantiats the Resources owned MyPrefab from memory. There are now 3 copies of MyPrefab: 1. On disk (stored in the executable) - the prefab template. 2. In memory (stored in Resources) - the prefab template, but ready to be used. 3. In memory (as an instance in the scene) - gameObj1, an independent copy of the Resources asset.
GameObject gameObj2 = Instantiate(Resources.Load("MyPrefab")) as GameObject;
Resources.Load() is called again on the same path. Are there now two Resources owned instances of the MyPrefab template in memory? Or does Unity realize that the asset has already been loaded, and just send me a copy of it to instantiate? If this is the case, what is the overhead like for Unity to determine that loading the asset is useless? Does it load it, then realize there are two copies and destroy one?
I'd highly doubt that they would load it then check if had already been loaded. Just saying that made me sick :(.
I was looking for confirmation that subsequent calls to load an asset simply return the reference to the already loaded asset. But now I can't find where it said that. I hope it wasn't in the release notes of the recent versions but I'll check and come back when I have your answer.
Hmm, went through the release notes but I couldn't find anything on it. I did find this post, although I can't be 100% sure since it isn't a Unity developer saying it.