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

2

6

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...

Fourgon answered 2/7, 2013 at 10:22 Comment(0)
T
9

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.

Tautology answered 2/7, 2013 at 14:58 Comment(2)
This is a great answer about the resources folder, though I'm still a bit confused about how I might use AssetBundles. I'll try loading things from the asset folder, and see how that does.Fourgon
AssetBundles are like a Resources folder you load at runtime from outside. You can load a bundle from a local source or a server. Once it is loaded you can access its assets much like the ones bundled at compile time inside the Resources folders. AssetsBundles are great to reduce the compiled application size and load dynamic content (most likely from a server) at runtime to make sure the user has the latest assets.Tautology
F
4

Great answer from Jerome about Resources. To add some additional info for future searches regarding AssetBundles, here are two scenarios:

Your game is too big

You have a ton of textures, say, and your iOS game is above 100 mb -- meaning Apple will show a warning to users and prevent them from downloading over cellular. Resources won't help because everything in that folder is bundled with the app.

Solution: Move the artwork you don't absolutely need on first-run into asset bundles. Build the bundles, upload them to a server somewhere, then download them at runtime as needed. Now your game is much smaller and won't have any scary warnings.

You need different versions of artwork for different platforms

Alternative scenario: you're developing for iPhone and iPad. For the same reasons as above you shrink your artwork as much as possible to hit the 100 mb limit for iPhone. But now the game looks terrible on iPad. What do?

Solution: You create an asset bundle with two variants. One for phones with low res artwork, and one for tablets with high res artwork. In this case the asset bundles can be shipped with the game or sent to a server. At run-time you pick the correct variant and load from the asset bundle, getting the appropriate artwork without having to if/else everywhere.

With all that being said, asset bundles are more complicated to use, poorly documented, and Unity's demos don't work properly at times. So seriously evaluate whether you need them.

Frontpage answered 16/2, 2017 at 1:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.