---
description: Trigger a function or event at a specific time during playback
---

# Event

{% embed url="https://youtu.be/3yVGE_rXeVw" %}

Events provide a way to invoke function calls during playback to implement custom behaviors. This is primarily used to initiate or end a state related to game play or other interactive applications.&#x20;

{% hint style="warning" %}
**Events only execute during playback**

An event is only triggered when Timeflow is playing continuously. This does not require entering Play Mode in Unity, unless the function being invoked is a runtime-only feature.
{% endhint %}

{% hint style="success" %}
Add an Event by right-clicking on the object in the Timeflow view and selecting: **Add Automation > Events > Timeflow Event**\
\
**Alternatively:**

Select a track section in the Track View and right-click to select **Events**.
{% endhint %}

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FISJ2SNySVPYNbHHxlowV%2Fimage.png?alt=media&#x26;token=59629cf1-b017-4160-ba55-c4697b5b7cec" alt=""><figcaption><p>Events are added at the current time and displayed as a small flag icon on the object <a href="../../../user-guide/timeflow-view/tracks">Track</a>.</p></figcaption></figure>

{% hint style="info" %}
Note that Events do not have any channels and instead appear like a keyframe on the track channel, as shown above.&#x20;
{% endhint %}

{% hint style="success" %}
Events have similar editing features to [keyframes ](../../../user-guide/timeflow-view/keyframes)and are included with [Related Keyframe](../../../../user-guide/timeflow-view/tracks#related-keyframes) operations.
{% endhint %}

## Editing Events in the Info Panel

Click on an event in the [Track View](../../../user-guide/timeflow-view/track-view) to view its settings in the [Info Panel](../../../user-guide/timeflow-view/info-panel). Please see the editor section below for more options and further explanation of each setting.

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2F7AybOlWciPC2UUJCC7B5%2Fimage.png?alt=media&#x26;token=58ac0e4d-f700-483b-91e8-71a4c71a6d59" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Multiple events may be selected at once for bulk editing in the Info Panel.
{% endhint %}

{% hint style="success" %}
**Goto**

Click the Goto button in the Info Panel or double-click on the event in the Track View to jump to the time of the event.&#x20;
{% endhint %}

## Event Editor

Select the game object to view Event settings in the Inspector. Events, like all other behaviors, are applied as components, with no limit on the number of events applied to each object.

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FBz938acmnZUOVg3DTLb1%2Fimage.png?alt=media&#x26;token=724aa14f-0cb7-4ad9-9fc2-f3f156a92882" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Events do not allow [Update Settings](../../../user-guide/timeflow-editor/update-settings) to be customized, otherwise it may not perform as expected or events may not trigger at all.
{% endhint %}

## Menu Bar

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FlKJDQGl35XPwJ7UxNWzP%2Fimage.png?alt=media&#x26;token=169b20c0-f6c5-4f18-81a0-de8611aa4f44" alt=""><figcaption></figcaption></figure>

Please refer to [Menu Bar](../../../user-guide/timeflow-editor/menu-bar) for common features.

### Event Name

Enter a name to help manage and identify events. This is for organizational purposes and is not required nor does it affect functionality.

### Triggered

Indicates when the event has been fired (checked) or not (unchecked). This gets reset upon start and when rewinding the timeline in edit mode.&#x20;

{% hint style="info" %}
Setting the Triggered checkbox manually overrides the internal tracking of whether or not the event has been fired. This may be useful while testing to allow or prevent an event from firing.
{% endhint %}

### Trigger Now

Use this to invoke the event function immediately bypassing any restriction on limit. This is used only for testing events.&#x20;

## Trigger Time

Sets the time the event is to be triggered during playback.&#x20;

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FUEXuKEysg4ECdsodrW8p%2Fimage.png?alt=media&#x26;token=4284ee8f-978d-4685-8fd1-8649db765aac" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Trigger Time is in local time which may be affected by [Time Offset](../../../user-guide/timeflow-view/time-offset).
{% endhint %}

### Set to Current Time

Assigns the event time using the current time of the playhead.

### Lock

Enable lock to prevent the event time from being changed. This also prevents dragging events in the [Track View](../../../user-guide/timeflow-view/track-view).

## Trigger Limit

Events may be limited to perform only a certain number of times during each run. This value may be left at 0 for the event to be fired without limit.&#x20;

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FvvY8HNWioydrkyElB6FQ%2Fimage.png?alt=media&#x26;token=896d1381-1572-49e2-8e0b-cc869832dfc1" alt=""><figcaption><p>To make sure an event only fires once, enter 1. Or enter any number the event is allowed to be retriggered.</p></figcaption></figure>

Under normal circumstances, Timeflow plays through just once and the limit is not needed. However, when looping sections of time or rewinding to replay from the beginning, this may be needed to ensure certain actions aren't repeated. &#x20;

{% hint style="info" %}
Trigger Limit is primarily used for interactive applications. For example, it could be used to display instructions to a user only the first time playing through a scene, but skipped on replays (during the same session). Or it could be used with other interactive contexts that limits the number of times a user is allowed to repeat actions.
{% endhint %}

{% hint style="warning" %}
**Trigger Limit is enforced at runtime only**\
When playing back Timeflow in edit mode, event triggers are reset each time rewinding the scene so that they fire each time played. This is much better for creative workflow while editing. However, during runtime (Play Mode) triggers are only initialized at start and never reset when rewinding or looping so that the Trigger Limit may be enforced.
{% endhint %}

## Send Message To

Uses [GameObject.SendMessage](https://docs.unity3d.com/ScriptReference/GameObject.SendMessage.html) to invoke the named method and optional parameter. This works in edit mode if the target method does.

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2Fw86k59m6HnhBkbbvAAug%2Fimage.png?alt=media&#x26;token=704c1386-8544-4988-bedb-42c49755c471" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
Note that the named function is invoked for every component on the Target object that implements it. If no component with the function is found, then it fails silently.
{% endhint %}

### Function and Parameter

Enter the exact name of the class method and leave blank or enter a parameter value to pass to the function when invoked. Below are examples showing how to implement methods in a component script.

```
public void MyMethod()
{
    Debug.Log("MyMethod");
}

public void MyMethod(string value)
{
    Debug.Log("MyMethod:" + value);
}
```

## OnTrigger()

Use [Unity Events](https://docs.unity3d.com/Manual/UnityEvents.html) to trigger any object or property value.&#x20;

<figure><img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FVp6NEKqOP1UCr2lfU9Zt%2Fimage.png?alt=media&#x26;token=429adb59-d950-44d0-bfc0-a37fd0ea8d70" alt=""><figcaption><p>Example using a trigger to deactivate an object. Use the + button to add more functions to the event.</p></figcaption></figure>

{% hint style="warning" %}
### Trigger State Reset

Note that there is no automatic mechanism to reset or undo actions performed by events, unless you add them in some manner. As in the example above, the Spaceship object is deactivated by the event, so would require another event or other mechanism to reactivate it. Otherwise, it will remain inactive. \
\
Whenever creating events that make unidirectional changes, it is recommended to have an initialization process or add another event that resets objects to their default states at the appropriate times.
{% endhint %}

{% hint style="info" %}
### Event Timing and Latency

During playback, the precise time of an Event may not exactly align to the current time due to frame rates and timing intervals. To determine when an event is triggered, Timeflow checks whether the event time falls within the last update time and the current time (ignoring explicit jumps in time).

In most cases the discrepancy between the set trigger time and the actual time triggered is microseconds. However, in cases where frame rate has dropped or playback is skipping for other reasons, the actual event time triggered may be delayed.
{% endhint %}

{% hint style="success" %}
### **Testing Events**

To test whether an event is firing, enable [debug logging](../../../../user-guide/timeflow-editor/menu-bar#debug-mode) in the Menu Bar and then play Timeflow uninterrupted over the event. The console log should output a message when the event is reached.\
<img src="https://2067910529-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC3dOuetlQfYgK5FPUKgn%2Fuploads%2FhdmZ3QgGMWTeYp0Eu4uB%2Fimage.png?alt=media&#x26;token=a676d09b-e5cc-448b-98ea-f704ea523111" alt="" data-size="original">

You may also press [Trigger Now](#trigger-now) at any point to fire an event, regardless of any limits set.
{% endhint %}

{% hint style="info" %}
### Event Scripting

The behavior is officially named TimeflowEvent so as to avoid ambiguity with other event types in Unity. Custom event implementations may also be created using TimeflowEvent as a base class. See TimeflowEvent.cs and [Scripting](../../scripting) for more information.
{% endhint %}
