Search Unity

[Solved] About File headers and Resources folder

Discussion in 'Editor & General Support' started by sandolkakos, Nov 24, 2015.

  1. sandolkakos

    sandolkakos

    Joined:
    Jun 3, 2009
    Posts:
    285
    Hi guys,

    We are developing an educational game to Android which have a big amount of images and sounds. These assets need to be loaded in real-time via path name that is defined in the SQLite database.

    At this moment we are optimizing the project in order to Unity build an APK file with smallest size possible, and analysing the Build informations in the Editor.log file, we got the following results:
    Code (csharp):
    1. Textures  246.1 mb    59.8%
    2. Meshes  911.8 kb    0.2%
    3. Animations  8.9 mb    2.2%
    4. Sounds  62.0 mb    15.1%
    5. Shaders  1.2 mb    0.3%
    6. Other Assets  6.1 mb    1.5%
    7. Levels  2.4 mb    0.6%
    8. Scripts  6.1 mb    1.5%
    9. Included DLLs 5.2 mb    1.3%
    10. File headers  72.2 mb    17.6%
    11. Complete size 411.4 mb    100.0%
    12.  
    13. ** The builded APK file size is: 126 mb **
    We have noticed that Unity is creating a big "File headers", because we have about 16.000 assets inner Resources folder (images and sounds). But we cannot move these assets out of Resources folder, because we need to load them by its path name that is defined in the SQLite database.

    So, my main question is:
    Is there any way to decrease the size of "File headers" without need to move the assets from Resources folder?
     
    Last edited: Nov 25, 2015
  2. chechoggomez

    chechoggomez

    Unity Technologies

    Joined:
    Feb 25, 2013
    Posts:
    91
    Hi @sandolkakos , I think there is no way to decrease the file header size without decreasing the amount of files in Resource Folders. So my suggestion to continue using file paths from database is to migrate to a different solution using local assetbundles instead using Resources folder, you still can use the file path to load the asset from Assetbundles.

    Take a look here:
    http://docs.unity3d.com/ScriptReference/AssetBundle.CreateFromFile.html
    http://docs.unity3d.com/Manual/BuildingAssetBundles5x.html
    http://docs.unity3d.com/Manual/LoadingAssetBundles.html

    in order to use AssetBundle.CreateFromFile on Android you need to store the Asset Bundle in an uncompressed .obb file and then use CreateFromFile with an offset.

    public static AssetBundle CreateFromFile(string path, int offset);

    This is for unity 4.6.x but it will be available in 5.3
    https://unity3d.com/es/unity/beta

    Unity5.3.0f2/Editor/Data/Documentation/en/ScriptReference/AssetBundle.LoadFromFile.html
    Unity5.3.0f2/Editor/Data/Documentation/en/ScriptReference/AssetBundle.LoadFromFileAsync.html
     
    sandolkakos likes this.
  3. frankn

    frankn

    Unity Technologies

    Joined:
    Nov 15, 2015
    Posts:
    10
    sandolkakos likes this.
  4. sandolkakos

    sandolkakos

    Joined:
    Jun 3, 2009
    Posts:
    285
    Hi @chechoggomez, thanks for your help.

    About file headers, thanks for the info now we can to change the focus.

    About the AssetBundles, the current version of the game which is running in the schools already is using the old AssetBundles 4.x, and it works fine, but in the last year we have a lot of problems with downloading additional content, because the internet connection in these schools is so slowly and unstable.

    Various situations have happened where the customer installs the APK, start the game and the additional content downloading never ends due their bad internet connection.

    Because of this, we are now trying to eliminate the need of download additional content, and we ended up in the big APK size problem.

    About .OBB, after your post, I have builded an APK + OBB and the result was outstanding, because the APK has about 18,5 MB and we can to continue executing the Resources.Load normally.

    Now, I have another questions:
    1. We dont host our App in the Play Store, because we send the APK to schools install manually. Is there the possibity to use .OBB in this situation?
    2. To each new Build we need to replace the .OBB file?
     
  5. frankn

    frankn

    Unity Technologies

    Joined:
    Nov 15, 2015
    Posts:
    10
    I have not seen this approach before, can you provide some more information? Is the offset needed to start after the OBB file header? Do you build the OBB file yourself?

    @sandolkakos: If you have access to the path <shared-storage>/Android/obb/<package-name>/ you can save the OBB there.
    https://developer.android.com/google/play/expansion-files.html#StorageLocation
     
    sandolkakos likes this.
  6. sandolkakos

    sandolkakos

    Joined:
    Jun 3, 2009
    Posts:
    285
    That is great, @frankn. We can now install it manually, but we are going to create some routines to the app download the OBB file from:
    1. USB
    2. Downloads folder
    3. URL Link

    With this, we can to give some options to the users which don't have a good internet connection.

    Another questions about the OBB:
    - We have a custom update system, where we can to create a new version only to replace a new picture or sound, for instance.

    1. Every time we build a new APK, we need also install the new OBB, or can we keep the old OBB running with the new APK?

    2. How to create the patch.obb? I can't find a post or tutorial about creating the patch.obb with Unity.
     
    Last edited: Dec 9, 2015
  7. sandolkakos

    sandolkakos

    Joined:
    Jun 3, 2009
    Posts:
    285