Documentation

Unity Engine

Download Unity

Unity Engine

BlobObjectExtensions

Extension methods for a BlobObject that you reference with a UnityObjectRef.
Read time 1 minuteLast updated 3 hours ago

Definition

public static class BlobObjectExtensions

Remarks

Use BlobObjectExtensions.AcquireReference when you hold the BlobObject as a UnityObjectRef<T>, for example in a component in the Entities package. The method returns a BlobObjectReference<T> that you dispose when you finish with it. To store data in the object, and for the type and version rules of the data, refer to
BlobObject.SetBlobAsset
.
The following example uses the
Unity.Animations
,
Unity.Entities
, and
UnityEngine
namespaces. It reads a custom blob through a
UnityObjectRef
to a
BlobObject
, and returns 0 if the reference is invalid.
Additional Resources: BlobObject, BlobObjectReference<T>

Examples

// This example reads the marker times of a BlobObject that a component holds as a UnityObjectRef.// A custom blob type can hold only unmanaged data, such as values and BlobArray fields.public struct MarkerTable{ public BlobArray<float> Times;}public static float SumMarkerTimes(UnityObjectRef<BlobObject> objectRef){ const int version = 1; // The reference is invalid if the object is missing, empty, or stores another version of the data. using BlobObjectReference<MarkerTable> reference = objectRef.AcquireReference<MarkerTable>(version); if (!reference.IsValid) { return 0f; } ref MarkerTable table = ref reference.Value; float sum = 0f; for (int i = 0; i < table.Times.Length; ++i) { sum += table.Times[i]; } return sum;}

Static Methods

Method

Description

AcquireReferenceAcquires a reference to the blob data stored in the object that a UnityObjectRef points to.