docs.unity3d.com
    Show / Hide Table of Contents

    Struct BlobBuilder

    Creates blob assets.

    Namespace: Unity.Entities
    Syntax
    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 (or a specialized unmanaged string type such as ).

    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>(Allocator) to create a reference to the blob asset in memory.
    9. Dispose the BlobBuilder object.

    Use the BlobAssetReference<T> returned by CreateBlobAssetReference<T>(Allocator) 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(Allocator, Int32)

    Constructs a BlobBuilder object.

    Methods

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

    Allocates enough memory to store length elements of struct T.

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

    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.

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

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

    ConstructRoot<T>()

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

    CreateBlobAssetReference<T>(Allocator)

    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)
    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023