GetSampleEntityId(int)
Gets the EntityId of the Unity object associated with the specified sample.
Read time 1 minuteLast updated 12 days ago
Definition
- Type: Method
- Namespace: UnityEditor.Profiling
- Assembly: UnityEditor.CoreModule
public EntityId GetSampleEntityId(int sampleIndex)
Parameters
Index of the Profiler sample.
Returns
Type | Description |
|---|---|
| EntityId | Returns the EntityId of the associated Unity object. Returns EntityId.None 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.
Note: Components might not have a defined name. If FrameDataView.GetUnityObjectInfo returns an empty name, check the FrameDataView.UnityObjectInfo.relatedGameObjectEntityId field and call FrameDataView.GetUnityObjectInfo again with that EntityId to get the GameObject's name.
Additional Resources: FrameDataView.GetUnityObjectInfo, EntityId, RawFrameDataView.GetSampleMarkerId.
Examples
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; } }}