Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 685
Catlard Avatar asked Jul 02 '13 10:07

Catlard


People also ask

Should I use Resources folder Unity?

Use Resources folder only when you really need to. Loading assets on demand will make your FPS rate drop, and having indirect dependencies is makes your work much more difficult. It's worth to mention again that these assets will always be included in your build, even if you don't use them.

What is difference between Resources and StreamingAssets folder Unity?

Streaming Assets : Any files placed in StreamingAssets are copied as it is to a particular folder on a target machine. Any asset placed inside StreamingAssets can be used while the application is running. Resources : Resources class allows you to find and access Objects including assets.

What should I put in my Resources folder?

The Resources folder in Figure 1 contains folders for storing binary files, data files, image files, and Include and Library folders that are used to store code used by external functions.

What is resource folder in Unity?

The Resources class allows you to find and access Objects including assets. In the editor, Resources. FindObjectsOfTypeAll can be used to locate assets and Scene objects. All assets that are in a folder named "Resources" anywhere in the Assets folder can be accessed via the Resources.


2 Answers

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.

like image 114
Jerome Maurey-Delaunay Avatar answered Sep 20 '22 21:09

Jerome Maurey-Delaunay


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.

like image 38
Alex Schearer Avatar answered Sep 21 '22 21:09

Alex Schearer