# EntityId

> A unique identifier for a Unity object.

## Definition

* **Type:** Struct
* **Namespace:** [UnityEngine](/engine/6000.7/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule
* **Implements:** [IEquatable\<EntityId>](https://learn.microsoft.com/dotnet/api/system.iequatable-1), [IComparable\<EntityId>](https://learn.microsoft.com/dotnet/api/system.icomparable-1), [IFormattable](https://learn.microsoft.com/dotnet/api/system.iformattable)

```csharp
public struct EntityId : IEquatable<EntityId>, IComparable<EntityId>, IFormattable
```

## Remarks

The internal representation of `EntityId` is an implementation detail and might change between versions. To ensure compatibility, avoid the following patterns:

* Casting `EntityId` to or from an integer type.
* Assuming any particular bit layout or sign conventions.
* Using `Object.GetHashCode` as a substitute for, or to derive, an `EntityId`.
* Serializing `EntityId` with `ToString` and deserializing with integer parsing.
* Sorting `EntityId` values to determine creation order.
* Manipulating individual bits of the `EntityId` value.

To work with `EntityId` values, use the provided API methods, such as [EntityId.ToULong](/engine/6000.7/script-reference/unityengine/entityid/toulong.md), [EntityId.FromULong](/engine/6000.7/script-reference/unityengine/entityid/fromulong.md), [EntityId.IsValid](/engine/6000.7/script-reference/unityengine/entityid/isvalid.md), [EntityId.Equals](/engine/6000.7/script-reference/unityengine/entityid/equals.md), and [EntityId.GetHashCode](/engine/6000.7/script-reference/unityengine/entityid/gethashcode.md).

**Note**: Code that previously used `InstanceID` as an integer should be updated to use the `EntityId` API methods instead.

## Static Properties

| Property                                                             | Description                                                                                                           |
| -------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| [None](/engine/6000.7/script-reference/unityengine/entityid/none.md) | Gets an EntityId that represents no valid Object or Entity. Use this to indicate an invalid or unassigned identifier. |

## Methods

| Method                                                                             | Description                                                        |
| ---------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
| [CompareTo](/engine/6000.7/script-reference/unityengine/entityid/compareto.md)     | Compares this EntityId to another EntityId.                        |
| [Equals](/engine/6000.7/script-reference/unityengine/entityid/equals.md)           | Determines whether the specified object is equal to this EntityId. |
| [GetHashCode](/engine/6000.7/script-reference/unityengine/entityid/gethashcode.md) | Returns a hash code for this EntityId.                             |
| [IsValid](/engine/6000.7/script-reference/unityengine/entityid/isvalid.md)         | Determines whether this EntityId represents a valid entity.        |
| [ToString](/engine/6000.7/script-reference/unityengine/entityid/tostring.md)       | Returns a string representation of this EntityId.                  |

## Static Methods

| Method                                                                         | Description                                                                                                                                                                                                                                                                 |
| ------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [FromULong](/engine/6000.7/script-reference/unityengine/entityid/fromulong.md) | Creates an [EntityId](/engine/6000.7/script-reference/unityengine/entityid.md) from raw ulong data. This should have come from another valid [EntityId](/engine/6000.7/script-reference/unityengine/entityid.md). (Use at your own risk. And bit arrangement might change.) |
| [ToULong](/engine/6000.7/script-reference/unityengine/entityid/toulong.md)     | Gets the raw data of the [EntityId](/engine/6000.7/script-reference/unityengine/entityid.md). (Use at your own risk. And bit arrangement might change.)                                                                                                                     |

## Operators

| Operator                                                                                     | Description                                                                   |
| -------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| [operator ==](/engine/6000.7/script-reference/unityengine/entityid/op-equality.md)           | Determines whether two EntityId instances are equal.                          |
| [operator >](/engine/6000.7/script-reference/unityengine/entityid/op-greaterthan.md)         | Determines whether the first EntityId is greater than the second.             |
| [operator >=](/engine/6000.7/script-reference/unityengine/entityid/op-greaterthanorequal.md) | Determines whether the first EntityId is greater than or equal to the second. |
| [operator !=](/engine/6000.7/script-reference/unityengine/entityid/op-inequality.md)         | Determines whether two EntityId instances are not equal.                      |
| [operator \<](/engine/6000.7/script-reference/unityengine/entityid/op-lessthan.md)           | Determines whether the first EntityId is less than the second.                |
| [operator \<=](/engine/6000.7/script-reference/unityengine/entityid/op-lessthanorequal.md)   | Determines whether the first EntityId is less than or equal to the second.    |
