---
title: "Starting Timeline Through a C# Script - 2019.3"
content_type: tutorial
url: "https://learn.unity.com/tutorial/starting-timeline-through-a-c-script-2019-3?language=en"
language: en
difficulty: beginner
duration_minutes: 15
unity_version:
  - "2019.4"
supported_unity_versions:
  - name: "2019.4"
    url: "https://learn.unity.com/tutorial/starting-timeline-through-a-c-script-2019-3.md?language=en&version=2019.4"
  - name: "2019.3"
    url: "https://learn.unity.com/tutorial/starting-timeline-through-a-c-script-2019-3.md?language=en&version=2019.3"
available_languages:
  - name: "en"
    url: "https://learn.unity.com/tutorial/starting-timeline-through-a-c-script-2019-3.md?language=en"
  - name: "ja"
    url: "https://learn.unity.com/tutorial/starting-timeline-through-a-c-script-2019-3-jp.md?language=ja"
last_updated: "2026-08-04T14:23:23.000Z"
---

# Starting Timeline Through a C# Script - 2019.3

Use a C# script to trigger and control a Timeline sequence through a Playable Director.

In this tutorial, we’ll start a Timeline using a Playable Director through a C# script.

## 1. Starting Timeline Through a C# Script

Verified in 2019.4

In this tutorial, we’ll start a Timeline using a Playable Director through a C# script. Starting a Timeline via script gives much greater control as to which Timeline is played and when. This is especially useful for cutscenes and interactive movies.


When controlling a Playable Director via script, callback functions can be invoked when the Playable Director is started and stopped. A common use is to disable player input and prevent NPC/enemy actions and movement when a cutscene is started, and to resume the game state after the Timeline has stopped.

Our script will also execute a callback function when the Timeline is started, and another when it’s stopped.

1\. Create a new GameObject by selecting **Create Empty** from the GameObject drop-down. Name it _Director_.

2\. Open the Timeline window by selecting **Sequencing** > **Timeline** from the Window drop-down.

3\. With Director selected, click **Create** to attach a Playable Director component and create a Timeline Asset (**Figure 01**).

![Figure 01: Creating a Director component and Timeline Asset](https://connect-mediagw.unity.com/h1/20210108/learn/images/d7245346-29c1-4f9e-95f5-6bb8279863f3_image5.png)

4\. Add and configure your desired animation tracks (**Figure 02**).

![Figure 02: Our Timeline, with a simple flyby animation](https://connect-mediagw.unity.com/h1/20210108/learn/images/f0377e10-84a4-48c2-93ce-55ea64956c0f_image6.png)

5\. Add a new Script component to Director, named _TimelinePlayer_, and open it in your script editor.

6\. Add the UnityEngine.Playables namespace:

```csharp
 using UnityEngine.Playables; 
```

7\. Inside the class definition, we’ll create references to the Playable Director and our control panel:

```csharp
private PlayableDirector director;
public GameObject controlPanel;
```

8\. Change Start to Awake, and delete the Update method.

9\. Inside Awake, we’ll set our Playable Director reference and register the callback functions, to be invoked when the Director is started and stopped:

```csharp
director = GetComponent<PlayableDirector>();
director.played += Director_Played;
director.stopped += Director_Stopped;
```

Director_Played and Director_Stopped, defined in the next two steps, are functions of return type void, whose only parameter is of type PlayableDirector.

10\. Director_Played will hide the UI panel used to start the Timeline once the Timeline has started playing.

```csharp
private void Director_Played(PlayableDirector obj)
{
    controlPanel.SetActive(false);
}
```

11\. Director_Stopped will show the UI panel after the Timeline has stopped.

```csharp
private void Director_Stopped(PlayableDirector obj)
{
    controlPanel.SetActive(true);
}
```

12\. Finally, we’re ready to define the function that starts the Timeline:

```csharp
public void StartTimeline()
{
    director.Play();
}
```

13\. The full script should look as follows:

```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;

public class TimelinePlayer : MonoBehaviour
{
    private PlayableDirector director;
    public GameObject controlPanel;

    private void Awake()
    {
        director = GetComponent<PlayableDirector>();
        director.played += Director_Played;
        director.stopped += Director_Stopped;
    }

    private void Director_Stopped(PlayableDirector obj)
    {
        controlPanel.SetActive(true);
    }

    private void Director_Played(PlayableDirector obj)
    {
        controlPanel.SetActive(false);
    }

    public void StartTimeline()
    {
        director.Play();
    }
} 
```

14\. Save changes and return to the Unity Editor.

15\. Create a UI button by selecting **UI** > **Button** from the GameObject drop-down.

16\. Click the **+** sign to add an OnClick event. Drag Director into the **Object** slot, and select **TimelinePlayer** > **StartTimeline()** (**Figure 03**).

![Figure 03: Adding the OnClick event to start the Timeline](https://connect-mediagw.unity.com/h1/20210108/learn/images/86dbc8af-ec81-415c-bf31-35a660bbfee7_image2.png)

17\. Select **Director** in the Hierarchy view. In the Timeline Player component of the Inspector, drag the button, or its parent canvas, into the slot labeled **Control Panel** (**Figure 04**).

![Figure 04: Timeline Player configured](https://connect-mediagw.unity.com/h1/20210108/learn/images/bc03c57e-4775-4a06-b0bf-00609f7e3a19_image4.png)

18\. Enter Play Mode and click the button to start the Timeline. While the Timeline is stopped, the button remains visible (**Figure 05**). While the Timeline is playing, it’s hidden (**Figure 06**). After the Timeline finishes playing, the button becomes visible once again.

![Figure 05: When the Timeline isn’t playing, the start button remains visible.](https://connect-mediagw.unity.com/h1/20210108/learn/images/8971bb29-9814-43c1-a0ad-ca562a51b34d_image3.png)

![Figure 06: When the Timeline is playing, the button is hidden.](https://connect-mediagw.unity.com/h1/20210108/learn/images/87151f87-3cb1-44b6-8836-be3a86ca086c_image1.png)

19\. Exit Play Mode.

## 2. Conclusion

 Timeline, an already versatile and powerful system, is further enhanced with scripting.
