# GetSessionMetaData

> Retrieves the metadata of the session this frame occurred in as a NativeArray.

## Definition

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

## GetSessionMetaData\<T>(Guid, int)

Retrieves the metadata of the session this frame occurred in as a NativeArray.

```csharp
public NativeArray<T> GetSessionMetaData<T>(Guid id, int tag) where T : struct
```

### Parameters

**** (\[Guid]\(https\://learn.microsoft.com/dotnet/api/system.guid)): Unique identifier associated with the data.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Data stream index.

### Returns

| Type                                                                                 | Description                                    |
| ------------------------------------------------------------------------------------ | ---------------------------------------------- |
| [NativeArray\<T>](/engine/6000.6/script-reference/unity/collections/nativearray1.md) | Returns the session metadata as a NativeArray. |

### Remarks

Use *GetSessionMetaData* to retrieve the data that the [Profiler.EmitSessionMetaData](/engine/6000.6/script-reference/unityengine/profiling/profiler/emitsessionmetadata.md) method wrote to the Profiler stream. Profiler data can contain frames from different sessions.

Use *id* to identify the metadata from your Project or package.

Use *tag* to distinguish between different data streams.

Use *index* to retrieve separate data chunks for each [Profiler.EmitSessionMetaData](/engine/6000.6/script-reference/unityengine/profiling/profiler/emitsessionmetadata.md) called during the profiling session.

```csharp
using System;
using Unity.Collections;
using UnityEditor.Profiling;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Profiling;

public class Example
{
    public struct TextureInfo
    {
        public int format;
        public int w;
        public int h;
    }

    public static readonly Guid MyProjectId = new Guid("7E1DEA84-51F1-477A-82B5-B5C57AC1EBF7");
    public static readonly int TextureInfoTag = 0;
    public static readonly int TextureDataTag = 1;

    public void EmitTextureToProfilerStream(Texture2D t)
    {
        TextureInfo textureInfo = new TextureInfo() { format = (int)t.format, w = t.width, h = t.height };
        NativeArray<byte> textureData = t.GetRawTextureData<byte>();
        Profiler.EmitSessionMetaData(MyProjectId, TextureInfoTag, new[] { textureInfo });
        Profiler.EmitSessionMetaData(MyProjectId, TextureDataTag, textureData);
    }

    public Texture2D GetSessionTextureFromProfilerStream(int frame)
    {
        using (var frameData = ProfilerDriver.GetRawFrameDataView(frame, 0))
        {
            NativeArray<TextureInfo> textureInfos = frameData.GetSessionMetaData<TextureInfo>(MyProjectId, TextureInfoTag);
            if (textureInfos.Length == 0)
                return null;

            NativeArray<byte> textureData = frameData.GetSessionMetaData<byte>(MyProjectId, TextureDataTag);
            if (textureData.Length == 0)
                return null;

            TextureInfo textureInfo = textureInfos[0];
            Texture2D texture = new Texture2D(textureInfo.w, textureInfo.h, (TextureFormat)textureInfo.format, false);
            texture.LoadRawTextureData(textureData);

            return texture;
        }
    }
}
```

**Note:**

The *FrameDataView* instance defines the lifetime of the returned ''NativeArray'. As such, if *FrameDataView* is disposed, all returned metadata becomes invalid and cannot be used. Copy data to a new *NativeArray* if you need it for longer duration.

Additional Resources: [Profiler.EmitSessionMetaData](/engine/6000.6/script-reference/unityengine/profiling/profiler/emitsessionmetadata.md).

## GetSessionMetaData\<T>(Guid, int, int)

Retrieves the metadata of the session this frame occurred in as a NativeArray.

```csharp
public NativeArray<T> GetSessionMetaData<T>(Guid id, int tag, int index) where T : struct
```

### Parameters

**** (\[Guid]\(https\://learn.microsoft.com/dotnet/api/system.guid)): Unique identifier associated with the data.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Data stream index.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Chunk index.

### Returns

| Type                                                                                 | Description                                    |
| ------------------------------------------------------------------------------------ | ---------------------------------------------- |
| [NativeArray\<T>](/engine/6000.6/script-reference/unity/collections/nativearray1.md) | Returns the session metadata as a NativeArray. |

### Remarks

Use *GetSessionMetaData* to retrieve the data that the [Profiler.EmitSessionMetaData](/engine/6000.6/script-reference/unityengine/profiling/profiler/emitsessionmetadata.md) method wrote to the Profiler stream. Profiler data can contain frames from different sessions.

Use *id* to identify the metadata from your Project or package.

Use *tag* to distinguish between different data streams.

Use *index* to retrieve separate data chunks for each [Profiler.EmitSessionMetaData](/engine/6000.6/script-reference/unityengine/profiling/profiler/emitsessionmetadata.md) called during the profiling session.

```csharp
using System;
using Unity.Collections;
using UnityEditor.Profiling;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Profiling;

public class Example
{
    public struct TextureInfo
    {
        public int format;
        public int w;
        public int h;
    }

    public static readonly Guid MyProjectId = new Guid("7E1DEA84-51F1-477A-82B5-B5C57AC1EBF7");
    public static readonly int TextureInfoTag = 0;
    public static readonly int TextureDataTag = 1;

    public void EmitTextureToProfilerStream(Texture2D t)
    {
        TextureInfo textureInfo = new TextureInfo() { format = (int)t.format, w = t.width, h = t.height };
        NativeArray<byte> textureData = t.GetRawTextureData<byte>();
        Profiler.EmitSessionMetaData(MyProjectId, TextureInfoTag, new[] { textureInfo });
        Profiler.EmitSessionMetaData(MyProjectId, TextureDataTag, textureData);
    }

    public Texture2D GetSessionTextureFromProfilerStream(int frame)
    {
        using (var frameData = ProfilerDriver.GetRawFrameDataView(frame, 0))
        {
            NativeArray<TextureInfo> textureInfos = frameData.GetSessionMetaData<TextureInfo>(MyProjectId, TextureInfoTag);
            if (textureInfos.Length == 0)
                return null;

            NativeArray<byte> textureData = frameData.GetSessionMetaData<byte>(MyProjectId, TextureDataTag);
            if (textureData.Length == 0)
                return null;

            TextureInfo textureInfo = textureInfos[0];
            Texture2D texture = new Texture2D(textureInfo.w, textureInfo.h, (TextureFormat)textureInfo.format, false);
            texture.LoadRawTextureData(textureData);

            return texture;
        }
    }
}
```

**Note:**

The *FrameDataView* instance defines the lifetime of the returned ''NativeArray'. As such, if *FrameDataView* is disposed, all returned metadata becomes invalid and cannot be used. Copy data to a new *NativeArray* if you need it for longer duration.

Additional Resources: [Profiler.EmitSessionMetaData](/engine/6000.6/script-reference/unityengine/profiling/profiler/emitsessionmetadata.md).
