EntityId
A unique identifier for a Unity object.
Read time 2 minutesLast updated 8 days ago
Definition
- Type: Struct
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
- Implements: IEquatable<EntityId>, IComparable<EntityId>
public struct EntityId : IEquatable<EntityId>, IComparable<EntityId>
Remarks
Unity assigns an to every object it loads or creates, and uses that identifier to refer to the object for as long as the object exists. To get the identifier of an object, use . To resolve an identifier back to an object, use Resources.EntityIdToObject.
EntityIdObject.GetEntityIdThe internal representation of is an implementation detail and might change between versions. To ensure compatibility, avoid the following patterns:
EntityId- Assuming any particular bit layout or sign conventions.
- Manipulating individual bits of the value.
EntityId - Sorting values to determine creation order.
EntityId - Using as a substitute for, or to derive, an
Object.GetHashCode.EntityId - Serializing with
EntityIdand deserializing with integer parsing.ToString
To work with values, use the provided API methods, such as EntityId.IsValid, EntityId.Equals, and EntityId.GetHashCode.
EntityIdEntityIdintEntityIdintEntityIdNote: Code that previously used as an integer should be updated to use the API methods instead.
InstanceIDEntityIdAdditional Resources: Migrate from InstanceID to EntityId.
Static Properties
Property | Description |
|---|---|
| None | Gets an EntityId that represents no valid Object or Entity. Use this to indicate an invalid or unassigned identifier. |
Methods
Method | Description |
|---|---|
| CompareTo | Compares this EntityId to another EntityId. |
| Equals | Determines whether the specified integer value is equal to this EntityId. |
| GetHashCode | Returns a hash code for this EntityId. |
| IsValid | Determines whether this EntityId is set to a value other than EntityId.None. |
| ToString | Returns a string representation of this EntityId. |
Operators
Operator | Description |
|---|---|
| operator == | Determines whether two EntityId instances are equal. |
| operator > | Determines whether the first EntityId is greater than the second. |
| operator >= | Determines whether the first EntityId is greater than or equal to the second. |
| EntityId | Implicitly converts an integer to an |
| int | Implicitly converts an |
| operator != | Determines whether two EntityId instances are not equal. |
| operator < | Determines whether the first EntityId is less than the second. |
| operator <= | Determines whether the first EntityId is less than or equal to the second. |