docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct BlobBuilder

    Creates blob assets.

    Namespace: Unity.Entities
    Assembly: Unity.Entities.dll
    Syntax
    public struct BlobBuilder
    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 (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 ConstructRoot<T>() 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 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 CreateBlobAssetReference<T>(AllocatorHandle) to create a reference to the blob asset in memory.
    9. Dispose the BlobBuilder object.

    Use the BlobAssetReference<T> returned by CreateBlobAssetReference<T>(AllocatorHandle) to reference the blob asset. You can use a BlobAssetReference<T> as a field of an IComponentData struct. More than one entity can reference the same blob asset.

    Call Dispose() 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.

    Examples

    Constructors

    Name Description
    BlobBuilder(AllocatorHandle, int)

    Constructs a BlobBuilder object.

    Properties

    Name Description
    IsCreated

    Returns true if this BlobBuilder has been allocated.

    Methods

    Name Description
    Allocate<T>(ref BlobArray<T>, int)

    Allocates enough memory to store length elements of struct T.

    Allocate<T>(ref BlobArray<T>, int, int)

    Allocates enough memory to store length elements of struct T.

    Allocate<T>(ref BlobPtr<T>)

    Allocates enough memory to store a struct of type T.

    ConstructRoot<T>()

    Creates the top-level fields of a single blob asset.

    Construct<T>(ref BlobArray<T>, params T[])

    Copies an array of structs to an array in a blob asset after allocating the necessary memory.

    CreateBlobAssetReference<T>(AllocatorHandle)

    Completes construction of the blob asset and returns a reference to the asset in unmanaged memory.

    Dispose()

    Disposes of this BlobBuilder instance and frees its temporary memory allocations.

    SetPointer<T>(ref BlobPtr<T>, ref T)

    Sets a BlobPtr to point to the given object inside the blob.

    Extension Methods

    BlobStringExtensions.AllocateString(ref BlobBuilder, ref BlobString, string)
    BlobStringExtensions.AllocateString<T>(ref BlobBuilder, ref BlobString, ref T)

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Constructors
    • Properties
    • Methods
    • Extension Methods
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)