# BlobBuilder

> Creates blob assets.

## Definition

* **Type:** Struct
* **Namespace:** [Unity.Entities](/engine/7000.0/script-reference/unity/entities.md)
* **Assembly:** UnityEngine.EntitiesModule
* **Implements:** [IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable)

```csharp
public struct BlobBuilder : IDisposable
```

## Remarks

A blob asset is an immutable data structure stored in unmanaged memory. Blob assets can contain primitive types, strings, structs, arrays, and arrays of arrays. Arrays and structs must only contain blittable types. Strings must be of type [BlobString](/engine/7000.0/script-reference/unity/entities/blobstring.md) (or a specialized unmanaged string type).

To use a BlobBuilder object to create a blob asset:

1. Declare the structure of the blob asset as a struct.
2. Create a BlobBuilder object.
3. Call the [BlobBuilder.ConstructRoot](/engine/7000.0/script-reference/unity/entities/blobbuilder/constructroot.md) method, where `T` is the struct defining the asset structure.
4. Initialize primitive values defined at the root level of the asset.
5. Allocate memory for arrays, structs, and [BlobString](/engine/7000.0/script-reference/unity/entities/blobstring.md) instances at the root.
6. Initialize the values of those arrays, structs, and strings.
7. Continue allocating memory and initializing values until you have fully constructed the asset.
8. Call [BlobBuilder.CreateBlobAssetReference](/engine/7000.0/script-reference/unity/entities/blobbuilder/createblobassetreference.md) to create a reference to the blob asset in memory.
9. Dispose the BlobBuilder object.

Use the [BlobAssetReference\<T>](/engine/7000.0/script-reference/unity/entities/blobassetreference1.md) returned by [BlobBuilder.CreateBlobAssetReference](/engine/7000.0/script-reference/unity/entities/blobbuilder/createblobassetreference.md) to reference the blob asset. You can use a [BlobAssetReference\<T>](/engine/7000.0/script-reference/unity/entities/blobassetreference1.md) as a field of an [IComponentData](/engine/7000.0/script-reference/unity/entities/icomponentdata.md) struct. More than one entity can reference the same blob asset.

Call [BlobAssetReference\<T>.Dispose](/engine/7000.0/script-reference/unity/entities/blobassetreference1/dispose.md) to free the memory allocated for a blob asset.

Blob assets cannot be modified once created. Instead, you must create a new blob asset, update any references to the old one and then dispose of it.

## Constructors

| Constructor                                                                                                                                        | Description                      |
| -------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- |
| [BlobBuilder(Unity.Collections.AllocatorManager.AllocatorHandle,System.Int32)](/engine/7000.0/script-reference/unity/entities/blobbuilder/ctor.md) | Constructs a BlobBuilder object. |

## Properties

| Property                                                                             | Description                                          |
| ------------------------------------------------------------------------------------ | ---------------------------------------------------- |
| [IsCreated](/engine/7000.0/script-reference/unity/entities/blobbuilder/iscreated.md) | Returns true if this BlobBuilder has been allocated. |

## Methods

| Method                                                                                                             | Description                                                                                        |
| ------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------- |
| [Allocate](/engine/7000.0/script-reference/unity/entities/blobbuilder/allocate.md)                                 | Allocates enough memory to store `length` elements of struct `T`.                                  |
| [Construct](/engine/7000.0/script-reference/unity/entities/blobbuilder/construct.md)                               | Copies an array of structs to an array in a blob asset after allocating the necessary memory.      |
| [ConstructRoot](/engine/7000.0/script-reference/unity/entities/blobbuilder/constructroot.md)                       | Creates the top-level fields of a single blob asset.                                               |
| [CreateBlobAssetReference](/engine/7000.0/script-reference/unity/entities/blobbuilder/createblobassetreference.md) | Completes construction of the blob asset and returns a reference to the asset in unmanaged memory. |
| [Dispose](/engine/7000.0/script-reference/unity/entities/blobbuilder/dispose.md)                                   | Disposes of this BlobBuilder instance and frees its temporary memory allocations.                  |
| [SetPointer](/engine/7000.0/script-reference/unity/entities/blobbuilder/setpointer.md)                             | Sets a BlobPtr to point to the given object inside the blob.                                       |
