How does Resources.Load work?

Is it possible to load an asset which is added to the Resources folder at run-time using Resources.Load?

The Resources folder doesn’t exist in builds; everything is compiled into an asset file or files (depending on how many levels you have). In other words, no. You can use asset bundles (Pro only) for much the same purpose.

–Eric

Orhhh … I see …

So if I have an asset bundle with 100 images in it … Assuming that I can save that asset bundle to disk … how do I say … load one image from that local asset bundle?

Wouldn’t I have to load the entire asset bundle, just to load one image?

For images you can use the WWW class (with a file:// prefix).

–Eric

I’m actually running the application on the iPad … and it shows on the Instruments Tool that …

There’s no memory allocation when I do something like … _myObject.renderer.material.mainTexture = (Texture2D)Resources.Load(“blahblahblah”);

So is there something as “powerful” as Resources.Load that doesn’t cause any increase in memory allocation when I try to load a local image file(which isn’t in the resources folder when built, and therefore no Resources.Load) … tbh, I don’t even understand how Resources.Load manages to do that … lol … T___T~

EDIT: I’ve a function which is something like:

So I’ve to load the image, and call that function with the image passed in as the argument …

Tried using www abc = new www(“file://path…”) … and doing SetImage(abc.texture) …
That increases the memory allocation …

Tried Texture2D tTex = new Texture2D(0,0,TextureFormat.ARGB32,false);
abc.LoadImageIntoTexture(tTex);
SetImage(tTex);
That increases the memory allocation as well …

As well as … using something like …
byte[ ] tBytes = System.IO.File.ReadAllBytes(“filepath…”);
Texture2D tTex = new Texture2D(0,0,TextureFormat.ARGB32,false);
tTex.LoadImage(tBytes);
SetImage(tTex);
But it still increases the memory allocation!!

So how in the world does Resources.Load() do it without increasing memory allocation?!?

b … u … m … p … :smile:

every loading of image increases memory allocation as it loads data to memory and VRAM

but U3 has a bug with loading textures from external (independent if you load image, www.texture or load into texture which all 3 are the same under the hood), which causes them to eat multiple times of what they should (when I last checked up to 10 times as much in the direct and indirect usage, i killed the app with out of memory on a freshly started itouch 3GS with 12 480x320 ARGB loaded without mipmap generation from IO bytes as well as www.bytes - case #370039 - still open and there recently has been some communication so I’m sure they are looking into it in some form)

as such only use from outside what really must be outside, put everything else into the application or use asset bundles if you are on iOS Pro

Hey, dreamora … Where can I see your reported case #370039? I would like to know when was that actually reported.

As for asset bundles, how am I supposed to use them correctly?
As far as I know, I can download the asset bundle using the WWW class … and use it from there on …
But how am I supposed to load something from an asset bundle that is cached locally, after it has completed downloading for the first time …

Let’s say … I’ve an asset bundle with 10images in it … so I’m gonna download it for the first time, and then cache it … so I’m probably going to load from that local asset bundle whenever I need one of the 10 images … What is the right way to do that?

Thanks …

b.u.m.p. :smile:

b.u.m.p. :frowning:

yes that would be the right way to do it.
load local if present, otherwise download and then load

So I would have to load the entire local asset bundle using the WWW class?
So that I can do something like:

If I’ve 100 images in that assetbundle, wouldn’t that be really costly just to load one image? ><‘’’

b.u.m.p. :smile:

b.u.m.p. :frowning:

If you want to load images individually then you can use the WWW class’s texture property, which returns the downloaded data as a Texture2D object. This is ideal for on-demand loading of images but you are restricted to JPG or PNG format.