Documentation

Unity Engine


Unity Engine


UnityObjectRef<T>

A utility structure that stores a reference to a UnityEngine.Object for Entities, so unmanaged components can hold one.
Read time 1 minuteLast updated 2 days ago

Definition

public struct UnityObjectRef<T> : IEquatable<UnityObjectRef<T>> where T : Object

Remarks

Stores the Object's EntityId, and subscenes serialize the asset references it holds. This is the recommended way to store references to Unity assets in Entities because it remains unmanaged.
Serialization is supported on IComponentData, ISharedComponentData and IBufferElementData.
As when a MonoBehaviour references an asset, asset garbage collection (such as Resources.UnloadUnusedAssets) doesn't unload a referenced asset.

Properties

Property

Description

EntityIdThe EntityId of the referenced object, or EntityId.None if it references nothing.
ValueThe Object this UnityObjectRef references.

Methods

Method

Description

EqualsChecks if this object references the same UnityEngine.Object as another object.
IsValidReturns true if the referenced Object still exists.

Static Methods

Method

Description

FromEntityIdCreates a reference to the object with the given EntityId.

Operators

Operator

Description

operator ==Returns true if two UnityObjectRef values are equal.
TImplicitly converts a UnityObjectRef to the UnityEngine.Object it references.
boolChecks whether the reference points to a valid object.
operator !=Returns true if two UnityObjectRef values are not equal.