Version: Unity 6.6 Alpha (6000.6)
LanguageEnglish
  • C#

RawFrameDataView.GetSampleEntityId

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public EntityId GetSampleEntityId(int sampleIndex);

Parameters

Parameter Description
sampleIndex Index of the Profiler sample.

Returns

EntityId Returns the EntityId of the associated Unity object. Returns EntityId.None if no object is associated with the sample.

Description

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; } } }