Lesson 82 +10 XP

Streaming Assets & File Sizes

Streaming Assets & File Sizes

Optimizing target binaries involves managing uncompressed database resources and minimizing build package footprints.

The StreamingAssets Folder

Sometimes, you need raw files to remain completely untouched during the build process:

  • Create a folder named "StreamingAssets" directly under the Assets directory.
  • Any files (such as raw video files, database files, or config text files) are copied byte-for-byte to the target build folder.
  • Accessing via Code:
  • Use Application.streamingAssetsPath to get the platform-specific directory.
  • On desktop platforms, read directly using standard C# File systems.
  • On Android and WebGL, the files are packaged inside an archive or hosted on a web server; you must load them asynchronously using UnityWebRequest.

Reducing Build File Sizes

To reduce the size of the final compiled game package:

  • Texture Compression: Change texture settings (e.g. ASTC for mobile, DXT for desktop) to reduce texture size.
  • Audio Compression: Use Vorbis compression for sounds and music to save space.
  • Asset Clean-up: Use the Build Report (located in the Editor Console window log after compilation) to see exactly which assets are taking up the most space.
  • IL2CPP Managed Stripping: Set Managed Stripping Level in Player Settings. Unity will strip unused classes and methods from the final DLL binaries to save space.

TL;DR

  • StreamingAssets stores files exactly as they are without formatting or compression.
  • Read StreamingAssets using UnityWebRequest on Android or WebGL targets.
  • Optimize build sizes by compressing textures, audio clips, and stripping unused C# code.
  • Check the console's Build Report to identify high-capacity assets.