Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Scriptable Build Pipeline Build Wrong AssetBundle While Scriptable Object Nest depth >= 2

Discussion in 'Asset Bundles' started by vergram96, Sep 4, 2023.

  1. vergram96

    vergram96

    Joined:
    Dec 8, 2020
    Posts:
    4
    1. What happened

    - given a custom scriptable object have a filed like MyScriptableObject m_RefObject, create 3 object named A, B, C.

    - C ref B, B ref A, use SBP CompatibilityBuildPipeline.BuildAssetBundles build 3 assets as individual bundle.

    - load bundle A, B, C, load asset A, B, C. Both A and B load success while load C fail, cause a warning ''The referenced script on this Behaviour (Game Object '<null>') is missing!'' and return null.

    - switch to UnityEditor.BuildPipeline.BuildAssetBundles both A, B, C load successfully.


    2. How to reproduce it using the example attached


    - open the Sample Scene and click Play, console will show the asset load failed, all the behavior inside Entry.cs

    version:
    • com.unity.scriptablebuildpipeline: 1.20.2/ 1.21.9
    • unity 2021.3.25f1

    @AndrewSkow
     

    Attached Files:

    Last edited: Sep 4, 2023
  2. vergram96

    vergram96

    Joined:
    Dec 8, 2020
    Posts:
    4
    here is the load code in the example.
    Code (CSharp):
    1.     public class Entry : MonoBehaviour
    2.     {
    3.         private void Start()
    4.         {
    5.             //      ref     ref
    6.             // so_2 -> so_1 -> so_0
    7.             var bundle0 = AssetBundle.LoadFromFile("Assets/StreamingAssets/so_0");
    8.             var bundle1 = AssetBundle.LoadFromFile("Assets/StreamingAssets/so_1");
    9.             var bundle2 = AssetBundle.LoadFromFile("Assets/StreamingAssets/so_2");
    10.  
    11.             // suppose all load success, but so_2 load failed return
    12.             LoadAsset(bundle0, "Assets/ScriptableObjects/so_0.asset"); // success
    13.             LoadAsset(bundle1, "Assets/ScriptableObjects/so_1.asset"); // success
    14.             LoadAsset(bundle2, "Assets/ScriptableObjects/so_2.asset"); // return null with a warning "The referenced script on this Behaviour (Game Object '<null>') is missing!"
    15.            
    16.             bundle2.Unload(true);
    17.             bundle1.Unload(true);
    18.             bundle0.Unload(true);
    19.         }
    20.  
    21.         void LoadAsset(AssetBundle bundle, string path)
    22.         {
    23.             var lowerPath = path.ToLower();
    24.             var asset = bundle.LoadAsset(lowerPath);
    25.             if (asset == null)
    26.             {
    27.                 Debug.LogError($"load {lowerPath} failed! bundle {bundle.name} path = {bundle.GetAllAssetNames()[0]}");
    28.             }
    29.             else
    30.             {
    31.                 Debug.Log($"load {lowerPath} success!");
    32.             }
    33.         }
    34. }
     
  3. vergram96

    vergram96

    Joined:
    Dec 8, 2020
    Posts:
    4
    inspect these bundles on AssetStudio can see both so_0, so_1 have a valid script path id, but so_2 doesn't.
    upload_2023-9-4_21-47-34.png upload_2023-9-4_21-48-6.png upload_2023-9-4_21-48-24.png