> ## Documentation Index
> Fetch the complete documentation index at: https://dacruzdev.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Animated GIF Recording with GifRecorder in ScreenshotKit

> Record and encode animated GIFs at runtime using the GifRecorder singleton: configure frame rate, quality, and palette, and wire up encoding events.

## Usage

```csharp theme={null}
using DaCruz.ScreenshotKit;
using UnityEngine;

public class GifController : MonoBehaviour
{
    public Camera cam;

    void StartGif()
    {
        var settings = new GifRecorder.RecordingSettings
        {
            SourceCamera     = cam,
            OutputPath       = Application.dataPath + "/../Captures/clip.gif",
            FrameRate        = 15,
            Resolution       = GifRecorder.Resolution.Half,
            MaxDuration      = 8f,
            Loop             = true,
            Quality          = GifEncoder.Quality.Medium,
            UseGlobalPalette = true,
        };

        GifRecorder.Instance.StartRecording(settings);

        GifRecorder.Instance.OnEncodingComplete += path =>
            Debug.Log($"GIF saved to {path}");
        GifRecorder.Instance.OnEncodingFailed += err =>
            Debug.LogError($"GIF failed: {err}");
    }

    void StopGif()
    {
        GifRecorder.Instance.StopRecording();        // starts encoding
        // or: GifRecorder.Instance.CancelRecording();
    }
}
```

## The singleton

The recorder runs as a singleton `MonoBehaviour` that survives scene loads (`DontDestroyOnLoad`).

**Properties for binding UI:** `State`, `RecordingTime`, `FrameCount`, `EncodingProgress`, `LastOutputPath`.

**Events:** `OnRecordingStarted`, `OnRecordingStopped`, `OnEncodingProgress`, `OnEncodingComplete`, `OnEncodingFailed`.

<Note>
  Encoding runs on a background thread after `StopRecording()`. The `.gif` file exists once `OnEncodingComplete` fires; watch `EncodingProgress` for a progress bar.
</Note>

<Warning>
  `GifRecorder` refuses to start outside Play Mode. The in-memory frame buffer is capped at 512 MB; the recorder caps the duration and logs a warning if your settings would exceed it.
</Warning>

## See also

* [GIF Recording workflow](/workflows/gif-recording) for the editor-window equivalent.
* [SequenceRecorder](/api/sequence-recorder) for frame-by-frame stills instead.
