---
title: "TimeLine 的 Internal_CreatePlayable 开销很大"
author: "石心.Yong"
published_by: "Perrin Yong"
canonical: https://www.pystone.net/notes/uwa-answer-timeline-internal-create-playable-cost/
type: note
content_role: source
source_type: "source"
visibility: public
id_stability: rename-stable
source_path: "10-计算机、信息技术与工程/05-游戏图形与运行时/我的UWA问答/2021-05-14 - TimeLine 的 Internal_CreatePlayable 开销很大.md"
content_hash: b1fe5062b1ce0737f527b92d1a51ee98dc7a55f9a853ed9ae902792aa0eaeb83
knowledge_version: 224c990773de.5fa8af6e39fa
site_commit: 224c990773de166d23a886306577dd90379529ce
notes_commit: 5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a
---
# TimeLine 的 Internal_CreatePlayable 开销很大

> **note · 我的 UWA 问答**
> 本文收录我在 UWA 问答发表的公开回答。问题内容归原提问者；回答保留当时语境，技术结论可能受 Unity 版本、平台和项目条件限制。

## 问题

我们的特效是使用TimeLine进行制作的，最近进行性能测试的时候发现，Internal_CreatePlayable 方法的开销很大，但是只有一个轨道，所以很迷惑这个开销跟什么有关

![OBQVIC13HDF4PR1T05K1.png](/media/a06868ea6ce1730acc01.png)

![VV0ERQW46F48AG~8RK`W.png](/media/6994e478fc316c2c49d3.png)

- 提问者：张红银
- 提问时间：2021-05-13 18:21:46

## 我的回答

Timline首次CreatePlayable就是比较耗时，我这边一个简单的Timeline资源首次耗时500+ms。

![image.png](/media/bc803d7ffb223c219887.png)

不过可以通过把CreatePlayable的步骤放在场景加载时进行来避免游戏过程中的卡顿。加载Timeline资源后，调用PlayableDirector.RebuildGraph就会进行CreatePlayable，相当于Prewarm。此后，再调用Play()，就不会进行CreatePlayable。再调用RebuildGraph，由于有了缓存，也不会有高耗时。

![image.png](/media/e340be29a46fa1428791.png)

下图为首次调用RebuildGraph的耗时。

![image.png](/media/06683ebaff63481a9344.png)

下图为第二次调用RebuildGraph的耗时。

![image.png](/media/337b214a077cdd1cde07.png)

- 回答时间：2021-05-14 19:51:53
- 最后更新：2021-05-14 19:51:53
- 采纳状态：未采纳

## 来源与关系

- 上位集合：[我的 UWA 问答](https://www.pystone.net/notes/my-uwa-answers/)
- UWA 标签：引擎技术
- 原始问题：[TimeLine 的 Internal_CreatePlayable 开销很大](https://answer.uwa4d.com/question/609c8d3a6bb31032f97916a9)
- 源页最后更新：2021-05-14 19:51:53
