# GetSampleEntityId(int)

> Gets the EntityId of the Unity object associated with the specified sample.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor.Profiling](/engine/6000.6/script-reference/unityeditor/profiling.md)
* **Assembly:** UnityEditor.CoreModule

```csharp
public EntityId GetSampleEntityId(int sampleIndex)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Index of the Profiler sample.

### Returns

| Type                                                                | Description                                                                                                                                                                            |
| ------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [EntityId](/engine/6000.6/script-reference/unityengine/entityid.md) | Returns the EntityId of the associated Unity object. Returns [EntityId.None](/engine/6000.6/script-reference/unityengine/entityid/none.md) if no object is associated with the sample. |

### Remarks

Many profiler samples are associated with specific Unity objects such as GameObjects, Components, or Assets. Use *GetSampleEntityId* to retrieve the unique identifier for the object that was active when the sample was recorded.

To get detailed information about the object (such as its name and type), use the returned EntityId with [FrameDataView.GetUnityObjectInfo](/engine/6000.6/script-reference/unityeditor/profiling/framedataview/getunityobjectinfo.md).

**Note:** Components might not have a defined name. If [FrameDataView.GetUnityObjectInfo](/engine/6000.6/script-reference/unityeditor/profiling/framedataview/getunityobjectinfo.md) returns an empty name, check the [FrameDataView.UnityObjectInfo](/engine/6000.6/script-reference/unityeditor/profiling/framedataview/unityobjectinfo.md).relatedGameObjectEntityId field and call [FrameDataView.GetUnityObjectInfo](/engine/6000.6/script-reference/unityeditor/profiling/framedataview/getunityobjectinfo.md) again with that EntityId to get the GameObject's name.

Additional Resources: [FrameDataView.GetUnityObjectInfo](/engine/6000.6/script-reference/unityeditor/profiling/framedataview/getunityobjectinfo.md), [EntityId](/engine/6000.6/script-reference/unityengine/entityid.md), [RawFrameDataView.GetSampleMarkerId](/engine/6000.6/script-reference/unityeditor/profiling/rawframedataview/getsamplemarkerid.md).

### Examples

```csharp
using UnityEditor.Profiling;
using UnityEditorInternal;
using UnityEngine;

public class Example
{
    public static string GetSampleObjectName(int frameIndex, int threadIndex, int sampleIndex)
    {
        using (var frameData = ProfilerDriver.GetRawFrameDataView(frameIndex, threadIndex))
        {
            if (!frameData.valid)
                return null;

            var entityId = frameData.GetSampleEntityId(sampleIndex);
            if (entityId == EntityId.None)
                return null;

            if (!frameData.GetUnityObjectInfo(entityId, out var objectInfo))
                return null;

            // For components, try to get the GameObject name if the component name is empty
            if (string.IsNullOrEmpty(objectInfo.name) &&
                objectInfo.relatedGameObjectEntityId != EntityId.None)
            {
                frameData.GetUnityObjectInfo(objectInfo.relatedGameObjectEntityId, out objectInfo);
            }

            return objectInfo.name;
        }
    }
}
```
