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
- Type: Struct
- Namespace: Unity.Entities
- Assembly: UnityEngine.CoreModule
- Implements: IEquatable<UnityObjectRef<T>>
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 |
|---|---|
| EntityId | The EntityId of the referenced object, or EntityId.None if it references nothing. |
| Value | The Object this UnityObjectRef references. |
Methods
Method | Description |
|---|---|
| Equals | Checks if this object references the same UnityEngine.Object as another object. |
| IsValid | Returns true if the referenced Object still exists. |
Static Methods
Method | Description |
|---|---|
| FromEntityId | Creates a reference to the object with the given EntityId. |
Operators
Operator | Description |
|---|---|
| operator == | Returns true if two UnityObjectRef values are equal. |
| T | Implicitly converts a UnityObjectRef to the UnityEngine.Object it references. |
| bool | Checks whether the reference points to a valid object. |
| operator != | Returns true if two UnityObjectRef values are not equal. |