A unique identifier for a Unity object.
Unity assigns an EntityId 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 Object.GetEntityId. To resolve an identifier back to an object, use Resources.EntityIdToObject.
The internal representation of EntityId is an implementation detail and might change between versions. To ensure compatibility, avoid the following patterns:
EntityId value.EntityId values to determine creation order.Object.GetHashCode as a substitute for, or to derive, an EntityId.EntityId with ToString and deserializing with integer parsing.To work with EntityId values, use the provided API methods, such as EntityId.IsValid, EntityId.Equals, and EntityId.GetHashCode.EntityId converts implicitly to and from int, so existing code that contains object identifiers in integers continues to compile. Store object identity in EntityId fields, parameters, and collection keys rather than in int values, and use the EntityId API instead of integer arithmetic.
Note: Code that previously used InstanceID as an integer should be updated to use the EntityId API methods instead.
Additional resources: Migrate from InstanceID to EntityId.
| Property | Description |
|---|---|
| None | Gets an EntityId that represents no valid Object or Entity. Use this to indicate an invalid or unassigned identifier. |
| Method | Description |
|---|---|
| CompareTo | Compares this EntityId to another EntityId. |
| Equals | Determines whether the specified object 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 None. |
| ToString | Returns a string representation of this EntityId. |
| Operator | Description |
|---|---|
| EntityId | Implicitly converts an integer to an EntityId. |
| int | Implicitly converts an EntityId to an integer. |
| operator != | Determines whether two EntityId instances are not equal. |
| operator < | Determines whether the first EntityId is less than the second. |
| operator == | Determines whether two EntityId instances are equal. |
| operator > | Determines whether the first EntityId is greater than the second. |
| Unknown operator | Determines whether the first EntityId is less than or equal to the second. |
| Unknown operator | Determines whether the first EntityId is greater than or equal to the second. |