Search Unity

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

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice

Help Wanted Build Task CalculateSceneDependencyData failed with exception: Object reference not set to an instan

Discussion in 'Addressables' started by Tirus, Dec 6, 2021.

  1. Tirus


    Aug 9, 2013
    I'm trying to implement terrain streaming with addressable scenes.

    My Setup:

    Unity 2021.2.3f1
    Addressables 1.19.13
    Scriptable Build Pipeline: 1.19.4

    I'm using Polaris to build my terrains, then I put each terrain tile in a subscene which shall then be loaded via addressables.
    So my Hierarchy looks something like this:

    In the world I have Monobehaviours that references these scenes and which are responsible for loading unloading my scenes (In editor and in Game):

    Code (CSharp):
    1.         public AssetReference sceneRef;
    2. ...
    3.         public void LoadSubScene()
    4.         {
    5. #if UNITY_EDITOR
    6.             if (!Application.isPlaying)
    7.             {
    8.                 if (!IsEnabledInEditor)
    9.                 {
    10.                     return;
    11.                 }
    12.                 EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath((SceneAsset)sceneRef.editorAsset),
    13.                     OpenSceneMode.Additive);
    14.                 return;
    15.             }
    16. #endif
    17.             if (sceneRef.IsValid())
    18.             {
    19.                 // Scene already loaded
    20.                 return;
    21.             }
    22.             sceneRef.LoadSceneAsync(LoadSceneMode.Additive).Completed += SceneLoadComplete;
    23.         }
    25. ....
    My Addressables look like this:
    with the following settings:

    My Problem:

    Code (csharp):
    1. Build Task CalculateSceneDependencyData failed with exception:
    3. Object reference not set to an instance of an object
    4.   at BuildCacheUtility.GetCacheEntry (System.Type type, System.Int32 version) [0x0001f] in C:\Projekte\Medievally\Library\PackageCache\com.unity.scriptablebuildpipeline@1.19.4\Editor\Utilities\BuildCacheUtility.cs:94
    5.   at UnityEditor.Build.Pipeline.Utilities.BuildCache.GetCacheEntry (System.Type type, System.Int32 version) [0x00001] in C:\Projekte\Medievally\Library\PackageCache\com.unity.scriptablebuildpipeline@1.19.4\Editor\Utilities\BuildCache.cs:203
    6.   at (wrapper delegate-invoke) System.Func`3[System.Type,System.Int32,UnityEditor.Build.Pipeline.Utilities.CacheEntry].invoke_TResult_T1_T2(System.Type,int)
    7.   at System.Linq.Enumerable+<SelectIterator>d__154`2[TSource,TResult].MoveNext () [0x0005a] in <61774763be294c9f8e2c781f10819224>:0
    8.   at System.Collections.Generic.HashSet`1[T].UnionWith (System.Collections.Generic.IEnumerable`1[T] other) [0x00026] in <61774763be294c9f8e2c781f10819224>:0
    9.   at UnityEditor.Build.Pipeline.Utilities.ExtensionMethods.ExtractCommonCacheData (UnityEditor.Build.Pipeline.Interfaces.IBuildCache cache, System.Collections.Generic.IEnumerable`1[T] includedObjects, System.Collections.Generic.IEnumerable`1[T] referencedObjects, System.Collections.Generic.HashSet`1[T] uniqueTypes, System.Collections.Generic.List`1[T] objectTypes, System.Collections.Generic.HashSet`1[T] dependencies) [0x000bf] in C:\Projekte\Medievally\Library\PackageCache\com.unity.scriptablebuildpipeline@1.19.4\Editor\Utilities\ExtensionMethods.cs:78
    10.   at UnityEditor.Build.Pipeline.Tasks.CalculateSceneDependencyData.GetCachedInfo (UnityEditor.GUID scene, System.Collections.Generic.IEnumerable`1[T] references, UnityEditor.Build.Content.SceneDependencyInfo sceneInfo, UnityEditor.Build.Content.BuildUsageTagSet usageTags, System.Collections.Generic.IEnumerable`1[T] prefabEntries, UnityEngine.Hash128 prefabDependency) [0x00030] in C:\Projekte\Medievally\Library\PackageCache\com.unity.scriptablebuildpipeline@1.19.4\Editor\Tasks\CalculateSceneDependencyData.cs:66
    11.   at UnityEditor.Build.Pipeline.Tasks.CalculateSceneDependencyData.Run () [0x0030d] in C:\Projekte\Medievally\Library\PackageCache\com.unity.scriptablebuildpipeline@1.19.4\Editor\Tasks\CalculateSceneDependencyData.cs:155
    12.   at UnityEditor.Build.Pipeline.BuildTasksRunner.Run (System.Collections.Generic.IList`1[T] pipeline, UnityEditor.Build.Pipeline.Interfaces.IBuildContext context) [0x000ca] in C:\Projekte\Medievally\Library\PackageCache\com.unity.scriptablebuildpipeline@1.19.4\Editor\Shared\BuildTasksRunner.cs:56
    13. UnityEditor.GenericMenu:CatchMenu (object,string[],int)
    I did some digging and the root of the problem seems to be that

    Code (CSharp):
    1. ContentBuildInterface.GetTypesForObject(objectId)
    returns null for my "GTerrainData" ScriptableObject from the Polaris Terrain library.
    However when I try to get the path from the guid, it returns a valid path:

    The asset in the projectview:

    The type "null" is then added to the "uniqueTypes" variable in "ExtensionMethods.ExtractCommonCacheData" and then
    Code (CSharp):
    1. dependencies.UnionWith(uniqueTypes.Select(cache.GetCacheEntry));
    is called and "cache.GetCacheEntry" throws a nullpointer, because type is null.

    Now I'm stuck since I dont have access to the Source of ContentBuild, so I don't really know why it returns null as type for this asset. It returns valid Types for all other ScriptableObjects from that library.

    What I tried so far

    I tried to purge all caches and to restart unity, delete my build game and then clean build and then build Addressables.
    Last edited: Dec 6, 2021
  2. Tirus


    Aug 9, 2013
    I added the TerrainData to an addressables group as well and now when I open the Groups window of addressables I get the following warning:


    Due to this I took a look at my asset and reimported it, now the project window shows that some Sub-Assets are actually null:

    It would be really nice if the Build could already warn me with a decent message, e.g.:
    "Building Addressable failed, because there is a null reference in the dependency: $guid and path $path.", this would have saved me a lot of debugging.

    However, now I am still stuck, because I don't know how the remove these null assets (or generally unused assets) from the root scriptable object. See this thread for reference:
    Last edited: Dec 7, 2021
  3. Tirus


    Aug 9, 2013
    I found the cause of the problem, which lies in the Polaris Terrain script.

    When "OnEnable" is called the script creates new textures that are then added to the TerrainData Asset with "AddToObject". However somehow this method produces a null asset when called during the addressables CalculateSceneDepedencyData (at least that is my guess where the null asset comes from).
    I managed to fix it by just removing the AddToObject calls from the OnEnable method, this way no "null" references get added to the scriptable Object during the Addressables build.

    It would still be nice to get more precise error messages from the addressables build, at least a path to the Asset where a null reference was detected, similar to the error message when you add an object with null references to an addressables group.