| Parameter | Description |
|---|---|
| sampleIndex | Index of the Profiler sample. |
EntityId Returns the EntityId of the associated Unity object. Returns EntityId.None if no object is associated with the sample.
Gets the EntityId of the Unity object associated with the specified sample.
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.
Note: Components might not have a defined name. If FrameDataView.GetUnityObjectInfo returns an empty name, check the UnityObjectInfo.relatedGameObjectEntityId field and call FrameDataView.GetUnityObjectInfo again with that EntityId to get the GameObject's name.
Additional resources: FrameDataView.GetUnityObjectInfo, EntityId, GetSampleMarkerId.
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; } } }