Struct BlobAssetReference<T>
A reference to a blob asset stored in unmanaged memory.
Namespace: Unity.Entities
Syntax
public struct BlobAssetReference<T> : IDisposable, IEquatable<BlobAssetReference<T>> where T : struct
Type Parameters
| Name | Description |
|---|---|
| T | The struct data type defining the data structure of the blob asset. |
Remarks
Create a blob asset using a BlobBuilder or by deserializing a serialized blob asset.
Properties
IsCreated
Reports whether this instance references a valid blob asset.
Declaration
public bool IsCreated { get; }
Property Value
| Type | Description |
|---|---|
| Boolean | True, if this instance references a valid blob instance. |
Null
A "null" blob asset reference that can be used to test if a BlobAssetReference instance
Declaration
public static BlobAssetReference<T> Null { get; }
Property Value
| Type | Description |
|---|---|
| BlobAssetReference<T> |
Value
A reference to the blob asset data.
Declaration
public T Value { get; }
Property Value
| Type | Description |
|---|---|
| T | The root data structure of the blob asset data. |
Remarks
The property is a reference return.
Methods
Create(T)
Creates a blob asset from an instance of a struct.
Declaration
public static BlobAssetReference<T> Create(T value)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | An instance of |
Returns
| Type | Description |
|---|---|
| BlobAssetReference<T> | A reference to newly created blob asset. |
Remarks
The struct must only contain blittable fields (primitive types, fixed-length arrays, or other structs
meeting these same criteria). The blob asset is created in unmanaged memory. Call Dispose() to
free the asset memory when it is no longer needed. This function can only be used in an
See Also
Create(Byte[])
Creates a blob asset from a byte array.
Declaration
public static BlobAssetReference<T> Create(byte[] data)
Parameters
| Type | Name | Description |
|---|---|---|
| Byte[] | data | The byte array containing the data to store in the blob asset. |
Returns
| Type | Description |
|---|---|
| BlobAssetReference<T> | A reference to newly created blob asset. |
Remarks
The blob asset is created in unmanaged memory. Call Dispose() to free the asset memory
when it is no longer needed. This function can only be used in an
See Also
Create(Void*, Int32)
Creates a blob asset from a pointer to data and a specified size.
Declaration
public static BlobAssetReference<T> Create(void *ptr, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| Void* | ptr | A pointer to the buffer containing the data to store in the blob asset. |
| Int32 | length | The length of the buffer in bytes. |
Returns
| Type | Description |
|---|---|
| BlobAssetReference<T> | A reference to newly created blob asset. |
Remarks
The blob asset is created in unmanaged memory. Call Dispose() to free the asset memory
when it is no longer needed. This function can only be used in an
See Also
Dispose()
Destroys the referenced blob asset and frees its memory.
Declaration
public void Dispose()
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown if you attempt to dispose a blob asset that loaded as part of a scene or subscene. |
Equals(Object)
Two BlobAssetReferences are equal when they reference the same data.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | obj | The object to compare to this reference |
Returns
| Type | Description |
|---|---|
| Boolean | True, if the object is a BlobAssetReference instance that references to the same data as this one, or if both objects are Null BlobAssetReference instances. |
Overrides
Equals(BlobAssetReference<T>)
Two BlobAssetReferences are equal when they reference the same data.
Declaration
public bool Equals(BlobAssetReference<T> other)
Parameters
| Type | Name | Description |
|---|---|---|
| BlobAssetReference<T> | other | The reference to compare to this one. |
Returns
| Type | Description |
|---|---|
| Boolean | True, if both references point to the same data or if both are Null. |
GetHashCode()
Generates the hash code for this object.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| Int32 | A standard C# value-type hash code. |
Overrides
GetUnsafePtr()
Provides an unsafe pointer to the blob asset data.
Declaration
public void *GetUnsafePtr()
Returns
| Type | Description |
|---|---|
| Void* | An unsafe pointer. The pointer is null for invalid BlobAssetReference instances. |
Remarks
You can only use unsafe pointers in
Release()
Declaration
public void Release()
TryRead(Byte[], Int32, out BlobAssetReference<T>)
Reads bytes from a buffer, validates the expected serialized version, and deserializes them into a new blob asset.
Declaration
public static bool TryRead(byte[] buffer, int version, out BlobAssetReference<T> result)
Parameters
| Type | Name | Description |
|---|---|---|
| Byte[] | buffer | Byte array of buffer |
| Int32 | version | Expected version number of the blob data. |
| BlobAssetReference<T> | result | The resulting BlobAssetReference if the data was read successful. |
Returns
| Type | Description |
|---|---|
| Boolean | A bool if the read was successful or not. |
TryRead(String, Int32, out BlobAssetReference<T>)
Reads bytes from a fileName, validates the expected serialized version, and deserializes them into a new blob asset.
Declaration
public static bool TryRead(string path, int version, out BlobAssetReference<T> result)
Parameters
| Type | Name | Description |
|---|---|---|
| String | path | The path of the blob data to read. |
| Int32 | version | Expected version number of the blob data. |
| BlobAssetReference<T> | result | The resulting BlobAssetReference if the data was read successful. |
Returns
| Type | Description |
|---|---|
| Boolean | A bool if the read was successful or not. |
Write(BlobBuilder, String, Int32)
Writes the blob data to a path with serialized version.
Declaration
public static void Write(BlobBuilder builder, string path, int verison)
Parameters
| Type | Name | Description |
|---|---|---|
| BlobBuilder | builder | The BlobBuilder containing the blob to write. |
| String | path | The path to write the blob data. |
| Int32 | verison |
Operators
Equality(BlobAssetReference<T>, BlobAssetReference<T>)
Two BlobAssetReferences are equal when they reference the same data.
Declaration
public static bool operator ==(BlobAssetReference<T> lhs, BlobAssetReference<T> rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| BlobAssetReference<T> | lhs | The BlobAssetReference on the left side of the operator. |
| BlobAssetReference<T> | rhs | The BlobAssetReference on the right side of the operator. |
Returns
| Type | Description |
|---|---|
| Boolean | True, if both references point to the same data or if both are Null. |
Inequality(BlobAssetReference<T>, BlobAssetReference<T>)
Two BlobAssetReferences are not equal unless they reference the same data.
Declaration
public static bool operator !=(BlobAssetReference<T> lhs, BlobAssetReference<T> rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| BlobAssetReference<T> | lhs | The BlobAssetReference on the left side of the operator. |
| BlobAssetReference<T> | rhs | The BlobAssetReference on the right side of the operator. |
Returns
| Type | Description |
|---|---|
| Boolean | True, if the references point to different data in memory or if one is Null. |