Unity 3D: Asset Bundles vs. Resources folder vs www.Texture

Catlard picture Catlard · Jul 2, 2013 · Viewed 23.3k times · Source

So, I've done a bit of reading around the forums about AssetBundles and the Resources folder in Unity 3D, and I can't figure out the optimal solution for the problem I'm facing. Here's the problem:

I've got a program designed for standalone, that loads "books" full of .png and .jpg images. The pages are, at the moment, the same every time the program starts. At the start of the scene for any "book", it's loading all those images at once using www.texture and a path. I'm realizing now, however, that this is possibly an non-performant method for accessing things at runtime -- it's slow! Which means the user can't do anything for 5-20 seconds while the scene starts and the book's page images load up (on non-legendary computers). SO, I can't figure out which of the three things would be the fastest:

1) Loading one asset bundle per book (say 20 textures @ 1 mb each).

2) Loading one asset bundle per page (1 mb each).

3) Either of the first two options, but loaded from the resources folder.

Which one would be faster, and why? I understand that asset bundles are packaged by unity, but does this mean that the textures inside will be pre-compressed and easier on memory at load time? Does the resources folder cause less load time? What gives? As I understand it, the resources folder loads into a cache -- but is it the same cache that the standalone player uses normally? Or is this extra, unused space? I guess another issue is that I'm not sure what the difference is between loading things from memory and storing them in the cache.

Cheers, folks...

Answer

Jerome Maurey-Delaunay picture Jerome Maurey-Delaunay · Jul 2, 2013

The Resource folders are bundled managed assets. That means they will be compressed by Unity, following the settings you apply in the IDE. They are therefore efficient to load at runtime. You can tailor the compression for each platform, which should further optimize performance.

We make expensive use of Resources.Load() to pull assets and it performs well on both desktop and mobile.

There is also a special folder, called StreamingAssets, that you can use to put bundled un-managed assets. This is where we put the videos we want to play at runtime, but don't want Unity to convert them to the default ogg codec. On mobile these play in the native video player. You can also put images in there and loading them is like using WWW class. Slow, because Unity needs to sanitize and compress the images at load time.

Loading WWW is slower due to the overhead of processing asset, as mentioned above. But you can pull data from a server or from outside the application "sandbox".

  • Only load what you need to display and implement a background process to fetch additional content when the user is busy going through the first pages of each book. This would avoid blocking the UI too long.
  • Optimize the images to reduce the file size. Use tinypng, if you need transparent images, or stick to compressed JPGs
  • Try using Power of 2 images where possible. This should speed up the runtime processing a little.

ath.