Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [1.21.23] - 2024-05-03
- Fixed issue where SpriteAtlas addressable bundle size is doubled if previous build cache is not cleared
  • Loading branch information
Unity Technologies committed May 3, 2024
1 parent 2c7db0f commit dd427a5
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.21.23] - 2024-05-03
- Fixed issue where SpriteAtlas addressable bundle size is doubled if previous build cache is not cleared

## [1.21.22] - 2024-02-08
- Fixed a bug where calculating scene dependency data could throw an error
- Fixed a bug that lead to builds being much slower than they should be
Expand Down
12 changes: 12 additions & 0 deletions Editor/Tasks/CalculateAssetDependencyData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,19 @@ static internal ReturnCode RunInternal(TaskInput input, out TaskOutput output)

HashSet<GUID> explicitAssets = new HashSet<GUID>(input.Assets);
Dictionary<GUID, AssetOutput> implicitAssetsOutput = new Dictionary<GUID, AssetOutput>();

// Populate the collection of packed sprites from the cache
HashSet<GUID> packedSprites = new HashSet<GUID>();
for (int i = 0; i < input.Assets.Count; i++)
{
if (cachedInfo != null && cachedInfo[i] != null)
{
var guid = input.Assets[i];
var spriteData = cachedInfo[i].Data[2] as SpriteImporterData;
if (spriteData != null && spriteData.PackedSprite)
packedSprites.Add(guid);
}
}

Queue<int> assetsToProcess = new Queue<int>();
for (int i = 0; i < input.Assets.Count; i++)
Expand Down
52 changes: 52 additions & 0 deletions Tests/Editor/CalculateAssetDependencyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,58 @@ public void WhenAssetRefsExplicitPackedSprite_AssetOnlyRefsSprite()
Assert.IsFalse(refsTexture, "Prefab should not reference the source texture.");
}

[Test]
public void WhenAssetRefsExplicitPackedSprite_CachedAssetOnlyRefsSprite()
{
var sprite = AssetDatabase.LoadAssetAtPath<Sprite>(kSpriteTexture1Asset);
var texture = AssetDatabase.LoadAssetAtPath<Texture>(kSpriteTexture1Asset);

string prefabName = "myPrefab.prefab";
string assetPath = Path.Combine(kTestAssetFolder, prefabName);
GameObject go = new GameObject(prefabName);
SpriteRenderer sr = go.AddComponent<SpriteRenderer>();
sr.sprite = sprite;
PrefabUtility.SaveAsPrefabAsset(go, assetPath);
UnityEngine.Object.DestroyImmediate(go, false);

string prefabGuidStr = AssetDatabase.AssetPathToGUID(assetPath);
AssetDatabase.TryGetGUIDAndLocalFileIdentifier(sprite, out string spriteGuidStr, out long spriteLocalId);
AssetDatabase.TryGetGUIDAndLocalFileIdentifier(texture, out string textureGuidStr, out long textureLocalId);
GUID prefabGuid = new GUID(prefabGuidStr);
GUID spriteGuid = new GUID(spriteGuidStr);
GUID textureGuid = new GUID(textureGuidStr);

EditorSettings.spritePackerMode = SpritePackerMode.BuildTimeOnlyAtlas;
CalculateAssetDependencyData.TaskInput input = CreateDefaultInput();
SpriteAtlasUtility.PackAllAtlases(input.Target);
input.Assets = new List<GUID>() { prefabGuid, spriteGuid };

using (BuildCache cache = new BuildCache())
{
cache.ClearCacheEntryMaps(); // needed if running multiple times
input.BuildCache = cache;

CalculateAssetDependencyData.RunInternal(input, out CalculateAssetDependencyData.TaskOutput output1);
cache.SyncPendingSaves();

CalculateAssetDependencyData.RunInternal(input, out CalculateAssetDependencyData.TaskOutput output2);
List<ObjectIdentifier> referencedObjs = output2.AssetResults[0].assetInfo.referencedObjects;
Assert.AreEqual(3, referencedObjs.Count);

bool refsSprite = false;
bool refsTexture = false;
foreach (ObjectIdentifier id in referencedObjs)
{
if (id.guid == spriteGuid && id.localIdentifierInFile == spriteLocalId)
refsSprite = true;
else if (id.guid == textureGuid && id.localIdentifierInFile == textureLocalId)
refsTexture = true;
}
Assert.IsTrue(refsSprite, "Prefab should reference the Sprite.");
Assert.IsFalse(refsTexture, "Prefab should not reference the source texture.");
}
}

[Test]
public void WhenAssetRefsExplicitSprite_AssetRefsSpriteAndTexture()
{
Expand Down
2 changes: 1 addition & 1 deletion ValidationExceptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"ValidationTest": "API Validation",
"ExceptionError": "",
"PackageVersion": "1.21.22"
"PackageVersion": "1.21.23"
}
]
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.unity.scriptablebuildpipeline",
"displayName": "Scriptable Build Pipeline",
"version": "1.21.22",
"version": "1.21.23",
"unity": "2019.4",
"description": "The Scriptable Build Pipeline moves the asset bundle build pipeline to C#. Use the pre-defined build flows, or create your own using the divided up APIs. This system improves build time, fixes incremental build, and provides greater flexibility.",
"keywords": [
Expand All @@ -14,15 +14,15 @@
],
"dependencies": {},
"_upm": {
"changelog": "- Fixed a bug where calculating scene dependency data could throw an error\n- Fixed a bug that lead to builds being much slower than they should be\n- Fixed issue where \"Build Task CalculateSceneDependencyData failed with exception: Object reference not set to an instance of an object\" is thrown when building."
"changelog": "- Fixed issue where SpriteAtlas addressable bundle size is doubled if previous build cache is not cleared"
},
"upmCi": {
"footprint": "04e9000332727dad441919b78ff684437b3fb0a2"
"footprint": "aee7003bf54ab54970da01a2e91fa79a4b23300f"
},
"documentationUrl": "https://docs.unity3d.com/Packages/[email protected]/manual/index.html",
"repository": {
"url": "https://github.cds.internal.unity3d.com/unity/Addressables.git",
"type": "git",
"revision": "6bd4bdae79fcdd3902dce37b766b3fae82d62fde"
"revision": "74ca1aaeb603da7437db95664f9bb92252223dab"
}
}

0 comments on commit dd427a5

Please sign in to comment.