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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

ScriptableObject not loading from AssetBundle

Discussion in 'Editor & General Support' started by ObliviousHarmony, Jan 26, 2016.

  1. ObliviousHarmony

    ObliviousHarmony

    Joined:
    Jul 3, 2014
    Posts:
    79
    Hey there,

    I've run into a small snag, and I was wondering if this was a bug or if perhaps I just did something wrong. I'm running Unity 5.3.1p4. Essentially, when I try to load the ScriptableObject, I get a warning "The referenced script on this Behaviour (Game Object '<null'>) is missing!" and the object is null. Here's the object:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class TestSerializeClassUnity : ScriptableObject
    5. {
    6.     [SerializeField]
    7.     private Vector3[] m_Vertices;
    8.  
    9.     public void Initialize()
    10.     {
    11.         m_Vertices = new Vector3[10000];
    12.     }
    13. }
    14.  
    Then the code that builds/load the asset bundle.
    Code (csharp):
    1.  
    2. using System;
    3. using System.Collections;
    4. using UnityEngine;
    5.  
    6. #if UNITY_EDITOR
    7. using UnityEditor;
    8. #endif
    9.  
    10. public class AssetBundlePerfTest : MonoBehaviour
    11. {
    12.     private static readonly string c_szBundlePath = Application.dataPath + "/TestAssets/testBundle.bun";
    13.  
    14. #if UNITY_EDITOR
    15.  
    16.     [MenuItem("Test/Prepare")]
    17.     private static void PrepareTest()
    18.     {
    19.         AssetDatabase.CreateFolder("Assets", "TestAssets");
    20.  
    21.         // prepare the Unity asset  and bundle that we will use to test Unity performance
    22.         TestSerializeClassUnity unityAsset = TestSerializeClassUnity.CreateInstance<TestSerializeClassUnity>();
    23.         unityAsset.Initialize();
    24.         AssetDatabase.CreateAsset(unityAsset, "Assets/TestAssets/CoreAsset.asset");
    25.         BuildPipeline.BuildAssetBundle(null, new UnityEngine.Object[] { unityAsset }, c_szBundlePath, BuildAssetBundleOptions.UncompressedAssetBundle);
    26.     }
    27.  
    28. #endif
    29.  
    30.     private void Start()
    31.     {
    32.         StartCoroutine(UnityPerfTest());
    33.     }
    34.  
    35.     private IEnumerator UnityPerfTest()
    36.     {
    37.         AssetBundleCreateRequest req = AssetBundle.LoadFromFileAsync(c_szBundlePath);
    38.         while (!req.isDone)
    39.             yield return null;
    40.  
    41.         AssetBundleRequest loadRq = req.assetBundle.LoadAssetAsync("coreasset.asset");
    42.         while (!loadRq.isDone)
    43.             yield return null;
    44.  
    45.         TestSerializeClassUnity obj = (TestSerializeClassUnity)loadRq.asset;
    46.  
    47.         req.assetBundle.Unload(true);
    48.     }
    49. }
    50.  
    I've also tried loading all of the assets, and the resulting array is empty. Anyone have any thoughts, or shall I go ahead and file a bug report?
     
  2. ObliviousHarmony

    ObliviousHarmony

    Joined:
    Jul 3, 2014
    Posts:
    79
    Update: I've tested the above scripts in several other versions of 5.x, and all of them had the same issue. I guess I'll have to work around this.
     
  3. ObliviousHarmony

    ObliviousHarmony

    Joined:
    Jul 3, 2014
    Posts:
    79
    Okay, it seems using the "CollectDependencies" flag causes this to work just fine. Not sure why you need to collect dependencies on a single asset like this, but who am I to judge :D Would be nice if the warning was more helpful though.
     
    NTG-Sera and Whippets like this.