BlobArray of BlobArray

I did not find anything on this topic besides this thread which does not directly answer my question. I was wondering wether there is a simpler approach than the one referred to in the thread which in the end still uses a flat array: Blob Hashmap

As I'm targeting sub-arrays with individual lengths avoiding flat arrays would be favoured - if possible.

In the documentation of entities 0.51 it says:
"Blob assets can contain primitive types, strings, structs, arrays, and arrays of arrays."

Let's assume we have this struct:

struct SomeStruct
{
    BlobArray<BlobArray<int>> array;
}

How would you allocate memory for this array with a given input array?

I tried variations of this:

int[][] inputArray;

BlobBuilder builder = new BlobBuilder(Allocator.Temp);
ref SomeStruct structRoot = ref builder.ConstructRoot<SomeStruct>();

BlobBuilderArray<BlobArray<int>> arrayBuilder = builder.Allocate(
    ref structRoot.array,
    inputArray.Length
);

for (int i = 0; i < inputArray.Length; i++)
{
    BlobBuilderArray<int> subArrayBuilder = builder.Allocate(
        ref arrayBuilder[i],
        inputArray[i].Length
    );
    for (int j = 0; j < inputArray[i].Length)
    {
        subArrayBuilder[j] = inputArray[i][j];
    }
}

But could not make it work - the referenced arrayBuilder in line 14 throws a nullref. I understand one can't simply use the new keyword for BlobArrays and that you need to allocate memory for the BlobArray using the BlobBuilderArray.

The other overload for BlobBuilder.Allocate with an alignment parameter is - as far as I understand - for optimizing memory access - so what am I missing here?

Maybe I'm missing something, but I have done something very similar to the code you have without issue. Could you provide a stack trace with the error you are getting?

Sure, SomeSystem:452 is equivalent to line 13 of the given sample code
This is the stack tracke:

NullReferenceException: Object reference not set to an instance of an object
SomeSystem.CreateBlobAssetReference () (at Assets/Scripts/Systems/SomeSystem.cs:452)
SomeSystem.OnCreate () (at Assets/Scripts/Systems/SomeSystem.cs:90)
Unity.Entities.ComponentSystemBase.CreateInstance (Unity.Entities.World world, Unity.Entities.SystemState* statePtr) (at Library/PackageCache/com.unity.entities@0.51.1-preview.21/Unity.Entities/ComponentSystemBase.cs:135)
Unity.Entities.World.AddSystem_OnCreate_Internal (Unity.Entities.ComponentSystemBase system) (at Library/PackageCache/com.unity.entities@0.51.1-preview.21/Unity.Entities/World.cs:340)
Unity.Entities.World.GetOrCreateSystemsAndLogException (System.Collections.Generic.IEnumerable1[T] types, System.Int32 typesCount) (at Library/PackageCache/com.unity.entities@0.51.1-preview.21/Unity.Entities/World.cs:542)
UnityEngine.Debug:LogException(Exception)
Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@0.51.1-preview.21/Unity.Entities/Stubs/Unity/Debug.cs:19)
Unity.Entities.World:GetOrCreateSystemsAndLogException(IEnumerable
1, Int32) (at Library/PackageCache/com.unity.entities@0.51.1-preview.21/Unity.Entities/World.cs:546)
Unity.Entities.DefaultWorldInitialization:AddSystemToRootLevelSystemGroupsInternal(World, IEnumerable1, ComponentSystemGroup, DefaultRootGroups) (at Library/PackageCache/com.unity.entities@0.51.1-preview.21/Unity.Entities/DefaultWorldInitialization.cs:221)
Unity.Entities.DefaultWorldInitialization:AddSystemToRootLevelSystemGroupsInternal(World, IEnumerable
1) (at Library/PackageCache/com.unity.entities@0.51.1-preview.21/Unity.Entities/DefaultWorldInitialization.cs:286)
Unity.Entities.DefaultWorldInitialization:Initialize(String, Boolean) (at Library/PackageCache/com.unity.entities@0.51.1-preview.21/Unity.Entities/DefaultWorldInitialization.cs:147)
Unity.Entities.AutomaticWorldBootstrap:Initialize() (at Library/PackageCache/com.unity.entities@0.51.1-preview.21/Unity.Entities.Hybrid/Injection/AutomaticWorldBootstrap.cs:16)

My understanding is that there shouldn't be cause for any NRE coming from trying to do something with the BlobBuilderArray indexer. Are you sure it's not an unset element of inputArray and the error is on 15?

You are absolutely right - that was indeed the issue here, some sub arrays were unset! My bad - should have checked that before!
Thank you both for the quick help.