-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## [1.21.25] - 2024-10-18 - Fixed issue where more than 2 Scriptable Objects are nested and Compatability Pipeline is used to build.
- Loading branch information
Unity Technologies
committed
Oct 18, 2024
1 parent
90acbff
commit 69978e2
Showing
14 changed files
with
248 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
using UnityEngine; | ||
using UnityEngine.Build.Pipeline; | ||
using Unity.ScriptableBuildPipelineTests; | ||
using NUnit.Framework; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace UnityEditor.Build.Pipeline.Tests | ||
{ | ||
[TestFixture] | ||
class BundleDependencyTests | ||
{ | ||
const string k_TmpAssetPath = "Assets/TempAssets"; | ||
const string k_BuildFolder = "TestBuild"; | ||
const int k_CntPrefabChain = 5; | ||
|
||
[OneTimeSetUp] | ||
public void Setup() | ||
{ | ||
Directory.CreateDirectory(k_TmpAssetPath); | ||
|
||
// Create scenario similar to BPSBP-740 | ||
|
||
var prefabRoots = new GameObject[k_CntPrefabChain]; | ||
|
||
for (int i = k_CntPrefabChain - 1; i >= 0; i--) | ||
{ | ||
var gameObject = new GameObject(); | ||
var mb = gameObject.AddComponent<MonoBehaviourWithReference>(); | ||
var prefabPath = $"{k_TmpAssetPath}/prefab{i}.prefab"; | ||
|
||
|
||
if (i != k_CntPrefabChain - 1) | ||
{ | ||
// Point to the next prefab in the chain | ||
mb.Reference = prefabRoots[i+1]; | ||
Assert.IsNotNull(mb.Reference); | ||
} | ||
else | ||
{ | ||
mb.Reference = gameObject; // Pointer to self, like in the original repro | ||
} | ||
|
||
prefabRoots[i] = PrefabUtility.SaveAsPrefabAsset(gameObject, prefabPath); | ||
AssetDatabase.ImportAsset(prefabPath, ImportAssetOptions.ForceSynchronousImport & ImportAssetOptions.ForceUpdate); | ||
} | ||
} | ||
|
||
[OneTimeTearDown] | ||
public void Cleanup() | ||
{ | ||
if (Directory.Exists(k_BuildFolder)) | ||
Directory.Delete(k_BuildFolder, true); | ||
|
||
AssetDatabase.DeleteAsset(k_TmpAssetPath); | ||
} | ||
|
||
static CompatibilityAssetBundleManifest BuildPrefabBundles(bool recurseDeps) | ||
{ | ||
// Put each prefab into its own AssetBundle | ||
var bundleDefinitions = new AssetBundleBuild[k_CntPrefabChain]; | ||
for (int i = 0; i < bundleDefinitions.Length; i++) | ||
{ | ||
bundleDefinitions[i].assetBundleName = $"{i}"; | ||
bundleDefinitions[i].assetNames = new string[] { $"{k_TmpAssetPath}/prefab{i}.prefab" }; | ||
}; | ||
|
||
if (Directory.Exists(k_BuildFolder)) | ||
Directory.Delete(k_BuildFolder, true); | ||
|
||
Directory.CreateDirectory(k_BuildFolder); | ||
|
||
// Todo, confirm that the NonRecursive Mode is enabled, the test assumes that it is and i think that is the default but its not exposed in this API | ||
|
||
var manifest = default(CompatibilityAssetBundleManifest); | ||
|
||
#if BUILD_OPTIONS_RECURSE_DEPENDENCIES_2022_3 || BUILD_OPTIONS_RECURSE_DEPENDENCIES_2023_3 || UNITY_6000_0_OR_NEWER | ||
if (recurseDeps) | ||
{ | ||
manifest = CompatibilityBuildPipeline.BuildAssetBundles( | ||
k_BuildFolder, | ||
bundleDefinitions, | ||
BuildAssetBundleOptions.AppendHashToAssetBundleName | BuildAssetBundleOptions.RecurseDependencies, | ||
EditorUserBuildSettings.activeBuildTarget); | ||
} | ||
else | ||
#endif | ||
{ | ||
manifest = CompatibilityBuildPipeline.BuildAssetBundles( | ||
k_BuildFolder, | ||
bundleDefinitions, | ||
BuildAssetBundleOptions.AppendHashToAssetBundleName, | ||
EditorUserBuildSettings.activeBuildTarget); | ||
} | ||
|
||
Assert.IsNotNull(manifest); | ||
|
||
return manifest; | ||
} | ||
|
||
#if BUILD_OPTIONS_RECURSE_DEPENDENCIES_2022_3 || BUILD_OPTIONS_RECURSE_DEPENDENCIES_2023_3 || UNITY_6000_0_OR_NEWER | ||
[Test, Description("BPSBP-737 / ADDR-3262")] | ||
public void MonoScriptsAreNotNullInChainedBundles() | ||
{ | ||
// Note: Test could also do variations, with MonoScript bundle enabled, maybe also NonRecursive=false | ||
CompatibilityAssetBundleManifest manifest = BuildPrefabBundles(true); | ||
|
||
string prefabBundleMatch = "*_*"; // Match bundle names like 0_f5b4234bbd5a5a599bd740802cc6f9cf and ignore other build output | ||
|
||
// All the prefabs as loaded from the assetbundles should have valid MonoBehaviour with non-null reference, matching | ||
// how we created them in the project. | ||
var builtBundlePaths = Directory.EnumerateFiles(k_BuildFolder, prefabBundleMatch, SearchOption.TopDirectoryOnly).ToArray(); | ||
LoadBundlesAndCheckMonoScript(builtBundlePaths); | ||
} | ||
#endif | ||
|
||
static void LoadBundlesAndCheckMonoScript(string[] bundleNames) | ||
{ | ||
var bundleCount = bundleNames.Length; | ||
var bundles = new AssetBundle[bundleCount]; | ||
for (int i = 0; i < bundleCount; i++) | ||
{ | ||
bundles[i] = AssetBundle.LoadFromFile(bundleNames[i]); | ||
} | ||
|
||
try | ||
{ | ||
for (int i = 0; i < bundleCount; i++) | ||
{ | ||
if (bundles[i].name == "UnityMonoScripts.bundle") | ||
continue; | ||
|
||
var prefab = bundles[i].LoadAllAssets<GameObject>()[0]; | ||
var monoBehaviour = prefab.GetComponent<MonoBehaviourWithReference>(); | ||
|
||
Assert.IsNotNull(monoBehaviour, "Missing MonoScript or MonoBehaviourWithReference on " + bundleNames[i]); | ||
|
||
var monoScript = MonoScript.FromMonoBehaviour(monoBehaviour); | ||
Assert.IsNotNull(monoScript); | ||
} | ||
} | ||
finally | ||
{ | ||
for (int i = 0; i < bundleCount; i++) | ||
bundles[i].Unload(true); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
21 changes: 15 additions & 6 deletions
21
Tests/Editor/Unity.ScriptableBuildPipeline.Editor.Tests.asmdef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
{ | ||
"name": "Unity.ScriptableBuildPipeline.Editor.Tests", | ||
"rootNamespace": "", | ||
"references": [ | ||
"Unity.ScriptableBuildPipeline.Editor", | ||
"Unity.ScriptableBuildPipeline", | ||
"Unity.PerformanceTesting", | ||
"Unity.PerformanceTesting.Editor" | ||
], | ||
"optionalUnityReferences": [ | ||
"TestAssemblies" | ||
"Unity.PerformanceTesting.Editor", | ||
"UnityEngine.TestRunner", | ||
"UnityEditor.TestRunner", | ||
"ScriptableBuildPipelineTests" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": true, | ||
"defineConstraints": [ | ||
"overrideReferences": true, | ||
"precompiledReferences": [ | ||
"nunit.framework.dll" | ||
], | ||
"autoReferenced": false, | ||
"defineConstraints": [ | ||
"UNITY_INCLUDE_TESTS", | ||
"UNITY_INCLUDE_TESTS" | ||
] | ||
], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace Unity.ScriptableBuildPipelineTests | ||
{ | ||
public class MonoBehaviourWithReference : MonoBehaviour | ||
{ | ||
public Object Reference; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "ScriptableBuildPipelineTests", | ||
"optionalUnityReferences": [ | ||
"TestAssemblies" | ||
], | ||
"defineConstraints": [ | ||
"UNITY_INCLUDE_TESTS" | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.24", | ||
"version": "1.21.25", | ||
"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": [ | ||
|
@@ -14,15 +14,15 @@ | |
], | ||
"dependencies": {}, | ||
"_upm": { | ||
"changelog": "Fix issue where build fails when not installed server platform is selected in the Build Settings Window\nFixed issue where total size of all bundles changes when updating the same Addressable Groups build." | ||
"changelog": "- Fixed issue where more than 2 Scriptable Objects are nested and Compatability Pipeline is used to build." | ||
}, | ||
"upmCi": { | ||
"footprint": "8cb47ea3786fb5bcc125c400a6f42a30e817a155" | ||
"footprint": "f72bee75ef137f73673bff7c5b2b8938cb684e8c" | ||
}, | ||
"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": "dc29b7795799cb70cc16868d4f07961052a3b033" | ||
"revision": "10cb5465c9d5eb7ae72cfc3c120116131c3852f0" | ||
} | ||
} |