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

# EncoreTrigger

> The Unity trigger host: place any trigger component by its ID above your game, and the members every trigger component shares.

The Unity form of the [trigger host](https://docs.encorekit.com/publishers/triggers/quickstart.md#the-trigger-host). An `EncoreTrigger` is a trigger view the SDK draws above the Unity view, at a screen rect your game sets. [`GiftsButton`](https://docs.encorekit.com/publishers/unity/sdk-reference/gifts-button) and [`ClaimReminder`](https://docs.encorekit.com/publishers/unity/sdk-reference/claim-reminder) derive from it, so the members on this page are theirs too.

## Signature

```csharp theme={null}
public class EncoreTrigger : IDisposable
{
    public static EncoreTrigger Create(string triggerId, string placement, TriggerOptions options = null);
    public float Height { get; }
    public event Action<float> HeightChanged;
    public event Action<PresentationResult> Result;
    public void SetFrame(Rect screenRect);
    public void SetVisible(bool visible);
    public void SetText(string headline, string subheadline = null, string cta = null);
    public void SetValues(IDictionary<string, string> values);
    public void SetAlignment(EncoreAlignment alignment);
    public void SetAppearance(AppearanceConfig appearance);
    public void Dispose();
}

public class TriggerOptions
{
    public UseCase UseCase = UseCase.RewardUsers;
    public bool AutoOpenOff;                    // forbids a look that opens its sheet by itself
    public string Headline;                     // null keeps the look's own text
    public string Subheadline;
    public string Cta;
    public Dictionary<string, string> Values;   // your words and numbers, by the names the look uses
    public TriggerIcon Icon = TriggerIcon.Gift;
    public EncoreAlignment Alignment = EncoreAlignment.Center; // across the width SetFrame gives
    public AppearanceConfig Appearance;         // the entry's colors, never the sheet's
}

public enum TriggerIcon { Gift, AppIcon, None }
public enum EncoreAlignment { Leading, Center, Trailing }
```

`Icon`, `Alignment`, and `Appearance` mean what they mean on every platform: see [Icon](https://docs.encorekit.com/publishers/triggers/overview.md#icon), [Width and alignment](https://docs.encorekit.com/publishers/triggers/overview.md#width-and-alignment), and [Colors](https://docs.encorekit.com/publishers/triggers/overview.md#colors). The types are [`AppearanceConfig`](https://docs.encorekit.com/publishers/unity/sdk-reference/appearance-config) and [`PresentationResult`](https://docs.encorekit.com/publishers/unity/sdk-reference/presentation-result).

## Members

| Member | Description |
| - | - |
| `Create(triggerId, placement, options)` | Creates the trigger with the ID you give, such as `giftsButton` or `claimReminder`. An ID the native SDK doesn't know shows nothing. Throws `ArgumentException` for a blank ID or placement. Created before `Encore.Configure`, it shows nothing |
| `SetFrame(screenRect)` | Places the trigger. The rect is in Unity screen space (origin bottom-left, as `Screen` and `RectTransformUtility` use). Only `x`, `y`, and `width` are used: the top sits at the top edge of the rect and the trigger takes its own height, so pass a height of 0 to put the top at `y` |
| `Height`, `HeightChanged` | The trigger's height in Unity screen pixels, and the event when it changes. Zero while there is nothing to show: no offers, a holdout, or an error |
| `SetVisible(visible)` | Hides or shows the trigger without removing it |
| `SetText(headline, subheadline, cta)` | Redraws the text in place. A null line falls back to the look's own text |
| `SetValues(values)` | Replaces the look's values, such as a countdown, and redraws. The text stays as it is |
| `SetAlignment(alignment)` | Moves the card across the width `SetFrame` gives |
| `SetAppearance(appearance)` | Redraws the entry in your colors. Null goes back to the look's own colors |
| `Result` | The result of each sheet the trigger opens, from a tap or an automatic open |
| `Dispose()` | Removes the trigger. Safe to call more than once |

`TriggerOptions.UseCase` defaults to `RewardUsers`, the use case trigger components support.

## Example

```csharp theme={null}
using EncoreKit;
using UnityEngine;

public class HomeScreen : MonoBehaviour
{
    private EncoreTrigger _trigger;

    private void Start()
    {
        _trigger = EncoreTrigger.Create("giftsButton", "home");
        _trigger.HeightChanged += height => Debug.Log($"Trigger height: {height}");
        _trigger.SetFrame(new Rect(40, Screen.height - 200, Screen.width - 80, 0));
    }

    private void OnDestroy() => _trigger?.Dispose();
}
```

## EncoreTriggerView

A `MonoBehaviour`, under **Add Component → Encore → Trigger**, that keeps the trigger with the ID you give over an empty `RectTransform` in your Canvas, and follows it every frame as the layout moves or scales. It waits for `Encore.Configure`, then creates the trigger in its first `LateUpdate` after that. [`EncoreGiftsButtonView`](https://docs.encorekit.com/publishers/unity/sdk-reference/gifts-button#encoregiftsbuttonview) and [`EncoreClaimReminderView`](https://docs.encorekit.com/publishers/unity/sdk-reference/claim-reminder#encoreclaimreminderview) work the same way, with the ID built in.

```csharp theme={null}
public sealed class EncoreTriggerView : EncoreTriggerViewBase
{
    public string TriggerId { get; set; }       // read once, when the trigger is created
}

public abstract class EncoreTriggerViewBase : MonoBehaviour
{
    public EncoreTrigger Trigger { get; }       // null until the trigger exists
    public string Placement { get; set; }       // read once, when the trigger is created
    public event Action<PresentationResult> Result;
}
```

| Inspector field | Default | Description |
| - | - | - |
| `triggerId` | `giftsButton` | `EncoreTriggerView` only. The trigger ID |
| `autoOpenOff` | off | `EncoreTriggerView` and `EncoreGiftsButtonView` only. Stops the trigger opening its sheet by itself |
| `placement` | `home` | The placement ID |
| `headline`, `subheadline`, `cta` | empty | Your text in place of the look's. Empty keeps the look's text |
| `icon` | `Gift` | The icon the look draws |
| `alignment` | `Center` | Where the card sits across the element's width. `SetAlignment` on the trigger changes it later |
| `resizeToContent` | on | Sets the element's height to the trigger's, and to zero when there is nothing to show |

Leave the element empty: the native trigger draws over it. Disabling the view hides the trigger, enabling it shows the trigger again, and destroying it removes the trigger. A blank ID or placement in the Inspector logs one error and disables the view.

## Notes

* The trigger draws above all Unity content. Hide it with `SetVisible(false)` while your game shows its own modal or pause screen.
* On iOS, trigger components draw only on iOS 17 or later. Below that the height stays 0.
* In the Unity Editor the trigger reports a height of 0 and draws nothing.
* On WebGL, `SetValues` and `SetAppearance` mount the trigger again instead of redrawing it in place.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.