Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Sprite Atlas Texture not included in built addressable bundle

Discussion in 'Addressables' started by jtaylorInfinityPlusTwo, Dec 20, 2019.

  1. jtaylorInfinityPlusTwo

    jtaylorInfinityPlusTwo

    Joined:
    Jun 9, 2016
    Posts:
    15
    Hi everyone,

    First off I'm using Unity 2019.1.14f1, and a slightly modified version of Addressables 1.3.8 so that Runtime Animator Controllers can load.

    I'm currently having an issue where sprites are not loading correctly, which results in what should be sprites simply displaying an entire atlas texture. This issue is compounded by the fact that only builds from our builds machines are having this issue. I can make a build on my local machine (whether using the .bat scripts that our build machines use, or through the editor itself), and the sprites will load correctly.

    For example, the below image is from a build on our build machines:
    SpriteAtlasBug_Actual_RemoteBuild.png

    And this image is from a build I made myself (and how it should look):
    SpriteAtlasBug_Intended_LocalBuild.png

    After investigating, I've found that the sprites that have this issue come from one of two atlases, which through browsing the built asset bundles I've found are missing their sprite atlas textures.

    The image below shows the breakdown of the assets from a bundle I built locally, which contains the atlas textures for SA_Items + SA_Professions, the two atlases having the issue.
    SpriteAtlasBug_LocalBundle_Contents_NoAtlasTexture_LI.jpg

    This image is from a bundle that our build machines built, in which the textures are not contained (yet you can see that other atlases contain their textures).
    SpriteAtlasBug_RemoteBundle_Contents_NoAtlasTexture.png

    I'm not exactly sure what I am missing here when it comes to our build machines, does anyone have any ideas on why those textures are not being included? For reference, this is what is being called on our build machines when they make builds:

    Code (CSharp):
    1.  
    2. public static void BuildAddressableAssets()
    3. {
    4.     // Reimport the sprite atlases.
    5.     string[] atlasDirectories = Directory.GetDirectories(Path.Combine(Application.dataPath, "Content\\Addressables\\SpriteAtlases"));
    6.     for (int i = 0; i < atlasDirectories.Length; i++)
    7.     {
    8.         string[] files = Directory.GetFiles(atlasDirectories[i]);
    9.         if (files == null || files.Length == 0)
    10.             continue;
    11.  
    12.         Console.WriteLine($"Reimporting {files.Length} assets in {atlasDirectories[i]}");
    13.         for (int j = 0; j < files.Length; j++)
    14.             AssetDatabase.ImportAsset(files[j]);
    15.     }
    16.  
    17.     // Pack the atlases.
    18.     Console.WriteLine("Packing sprite atlases");
    19.     SpriteAtlasUtility.PackAllAtlases(EditorUserBuildSettings.activeBuildTarget, false);
    20.  
    21.     AddressableAssetSettings AddressablesSettings = (AddressableAssetSettings)AssetDatabase.LoadAssetAtPath(EditorHelperFunctions.Addressables.AddressableSettingsFilePath, typeof(AddressableAssetSettings));
    22.  
    23. #if UNITY_IOS || UNITY_ANDROID
    24.     string profileId = AddressablesSettings.profileSettings.GetProfileId("Mobile");
    25. #else
    26.     string profileId = AddressablesSettings.profileSettings.GetProfileId("Default");
    27. #endif
    28.  
    29.     Console.WriteLine("Setting addressables profile to " + AddressablesSettings.profileSettings.GetProfileName(profileId));
    30.     AddressablesSettings.activeProfileId = profileId;
    31.  
    32.     try
    33.     {
    34.         int previousActiveDataBuildIndex = AddressablesSettings.ActivePlayerDataBuilderIndex;
    35.         AddressablesSettings.ActivePlayerDataBuilderIndex = 0;
    36.         Console.WriteLine("Set addressable build script to " + AddressablesSettings.ActivePlayerDataBuilder.Name);
    37.  
    38.         Console.WriteLine("Cleaning Addressable Assets...");
    39.         AddressableAssetSettings.CleanPlayerContent(AddressablesSettings.ActivePlayerDataBuilder);
    40.  
    41.         Console.WriteLine("Building Addressable Assets...");
    42.         AddressableAssetSettings.BuildPlayerContent();
    43.  
    44.         Console.WriteLine("Addressable Asset building complete.");
    45.         AddressablesSettings.ActivePlayerDataBuilderIndex = previousActiveDataBuildIndex;
    46.         Console.WriteLine("Set addressable build script to previous mode: " + AddressablesSettings.ActivePlayerDataBuilder.Name);
    47.    }
    48.    catch (Exception e)
    49.    {
    50.         Console.WriteLine("Exception caught when attempting to build addressable assets - this may have resulted in incorrect assets in the build! Caught Ex:");
    51.         Debug.LogException(e);
    52.     }
    53. }
     
  2. Shaunyowns

    Shaunyowns

    Joined:
    Nov 4, 2019
    Posts:
    328
  3. jtaylorInfinityPlusTwo

    jtaylorInfinityPlusTwo

    Joined:
    Jun 9, 2016
    Posts:
    15
    Hi @Shaunyowns, thank you for that! I was planning on updating to 2019.3 and the Addressables package before I bumped the thread to see if it fixes it, haha. Look forward to any reply.
     
  4. jtaylorInfinityPlusTwo

    jtaylorInfinityPlusTwo

    Joined:
    Jun 9, 2016
    Posts:
    15
    Hey @Shaunyowns, I believe we've found what was causing our issues. We removed the code about reimporting and repacking sprite atlases at the top (Lines 4 - 19 in the code provided at the top) before building our addressable assets, and found that the atlases are working again in-game.
     
  5. Shaunyowns

    Shaunyowns

    Joined:
    Nov 4, 2019
    Posts:
    328
  6. jtaylorInfinityPlusTwo

    jtaylorInfinityPlusTwo

    Joined:
    Jun 9, 2016
    Posts:
    15
    Hi @Shaunyowns, Unfortunately seems I spoke too soon. :( It seems to have reared its head once again (but with different atlases this time!).
    It appears as if the Atlas's sprite texture is not being included with the resulting bundle when built through command line on a fresh import of the project (no library folder/fresh checkout). However, I can clean all addressable builders (Addressable Groups window > Build > Clean > All), and build assets through the Editor itself and it builds correctly.

    In our build script, I've changed our clean assets to no longer take in the Active player data builder, so that it will clean everything as well, but still persists as an issue. Any help would be appreciated though! Has been a thorn.
     
  7. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    @Shaunyowns @jtaylorInfinityPlusTwo I'm having this same issue. Any solution that was found?
     
    Last edited: Apr 25, 2020
  8. jtaylorInfinityPlusTwo

    jtaylorInfinityPlusTwo

    Joined:
    Jun 9, 2016
    Posts:
    15