0
\$\begingroup\$

I have a game with lots of assets, such as data files, images, etc. My understanding is that Unity is optimized to know about all resources at build time. i.e. binding those assets to Scene GameObjects or prefabs. And for performance reasons, dynamically loading files from the /Resources folder is discouraged.

My question is how can I set up a "content pipeline" for converting my asset files stored outside of Unity into a format that Unity expects.

With the XNA toolset you can create a separate project and "build" the content into a bundle. Is there way to achieve similar results in Unity? Or is the best I can do creating an external tool, and simply copying files into my Unity/Textures or Unity/DataFiles folder and generate the Unity metadata files myself?

If there isn't an off-the-shelf solution, do you have any experiences or recommendations with solving this problem?

\$\endgroup\$
  • 1
    \$\begingroup\$ Can you give some examples of the kinds of assets you want to use which aren't already handled by Unity's content management system? \$\endgroup\$ – DMGregory Mar 16 '14 at 17:23
  • 1
    \$\begingroup\$ "dynamically loading files from the /Resources folder is discouraged", not entirely. Really this is only if included assets you're not using. As far as I know, it only increases the size of the deploy because Unity doesn't know which assets are being used, so it just includes them all. \$\endgroup\$ – MichaelHouse Mar 16 '14 at 17:34
  • \$\begingroup\$ Also with regards the Resources folder, read the comments on my answer here gamedev.stackexchange.com/a/69081/6588 \$\endgroup\$ – jhocking Mar 16 '14 at 20:47
  • \$\begingroup\$ oh wait you asked that question too. So considering you already asked that previous question, why do you still think loading files from Resources is a problem? Also, where did you get that impression anyway, that loading from Resources is discouraged? I'd like to see what exactly was said, so that I can make sure I'm not missing something about that performance. \$\endgroup\$ – jhocking Mar 16 '14 at 20:50
  • \$\begingroup\$ Very often you will find that Unity lets you configure things to your needs. Per-texture you can select compression and size per-platform for example. However if this doesn't suit you, you can write editor scripts to copy your files to their proper place (I do this to set up Android plugins for different configurations), and you can use unity's API to configure the assets. \$\endgroup\$ – maul Mar 16 '14 at 21:19
1
\$\begingroup\$

As others have said, there doesn't really seem to be any reason to believe that loading files from the /Resources folder is discouraged. The only other difference between /Resources and assets bound to GameObjects that I can think of is that assets bound to GameObjects are loaded with the scene, and assets in /Resources are loaded using Resources.Load(), so you'll have to be careful about when you call that.

But, in interest of answering your question, one thing you could try is to put your 'other' assets into another Unity project, and then package them up into one or more AssetBundles. You could then either include the bundle in the 1st project, or fetch it from a remote source, and unpackage it at runtime.

\$\endgroup\$
0
\$\begingroup\$

My little stone to the pyramid.
- Resources:
Already discussed in other posts.
- AssetBundle:
For big games on mobile platforms, it helps reducing the size of the build. At runtime, you can download a scene, a model, HD-textures, ... and load or instantiate. It's a nice option and the closest one(Subjective) to your XNA-toolset-bundle.
- StreamingAssets:
I use streamingAssets for files not linked to a gameObject. A little code-snippet:

public static string BundleFilePath(string filename) {
      string result;
      #if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
      result = Path.Combine(string.Format("file://{0}", Application.streamingAssetsPath), filename);
      #elif UNITY_ANDROID
      result = System.IO.Path.Combine(Application.streamingAssetsPath, filename);
      #elif UNITY_IPHONE
      result = System.IO.Path.Combine(Application.dataPath, string.Format("Raw/{0}", filename));
      #elif UNITY_WEBPLAYER
      result = System.IO.Path.Combine("StreamingAssets/", filename)); // untested
      #endif
      return result;
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.