Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

PrimeTween

> 编程语言
Open source

High-performance, allocation-free tween library for Unity. Create animations, delays, and sequences in one line of code.

2.0K stars0 likes0 views
WebsiteGitHub

About

High-performance, allocation-free tween library for Unity. Create animations, delays, and sequences in one line of code.

PrimeTween

PrimeTween is a high-performance, allocation-free animation library for Unity. Animate anything with just one line of code, tweak all animation properties directly from the Inspector, and create complex animation sequences. No runtime memory allocations, ever.

Get PrimeTween PRO to animate anything without code.

Performance comparison with other tween libraries.

Asset Store | Forum | FAQ | YouTube

Table of Contents

  • Getting started
    • Installation
    • Animations
    • Shakes
    • Callbacks
    • Delays
    • Cycles
  • PrimeTween PRO
    • Tween Animation
    • Tween Animation Component
    • Per-object material animations
  • Sequencing tweens
    • Sequence
    • Coroutines
    • Async/await
  • Controlling tweens
  • Inspector integration
  • Advanced
    • Custom tweens
    • Timescale
    • OnUpdate
    • Speed-based animations
    • Custom easing
    • LateUpdate/FixedUpdate
    • Install via Unity Package Manager (UPM)
    • Zero allocations with delegates
    • Debugging tweens
  • Migrating from DOTween to PrimeTween
    • Performance comparison
    • DOTween adapter
    • Tween.PlayForward/PlayBackwards
    • Migration cheatsheet
  • Support

Getting started

Installation

Import PrimeTween from Asset Store. This is a preferable option because it comes with a Demo scene.
Optional: install via Unity Package Manager (UPM).

Animations

Without further ado, let's jump straight to the code!

csharp
using PrimeTween;

// Animate 'transform.position.y' from the current value to 10 in 1 second using the Ease.InOutSine
Tween.PositionY(transform, endValue: 10, duration: 1, ease: Ease.InOutSine);

// Rotate 'transform' from the current rotation to (0, 90, 0) in 1 second
Tween.Rotation(transform, endValue: Quaternion.Euler(0, 90, 0), duration: 1);

// Rotate 'transform' around the y-axis by 360 degrees in 1 second 
Tween.EulerAngles(transform, startValue: Vector3.zero, endValue: new Vector3(0, 360), duration: 1);

That's it!

Simply type Tween. and let your IDE suggest all supported animations. Out of the box, PrimeTween can animate almost everything: UI, UI Toolkit, Materials, Camera properties, Transforms, AudioSource, and whatnot.

Didn't find what you're looking for? No problem, use Tween.Custom() to animate anything.

To view PrimeTween's XML documentation in your IDE, enable this setting: 'Unity Preferences/External Tools/Generate .csproj files for/Local tarball' and press the 'Regenerate project files' button.

Shakes

…

Callbacks

Use .OnComplete() to execute custom code on tween's completion.

csharp
// Call SomeMethod() when the animation completes
Tween.Position(transform, endValue: new Vector3(10, 0), duration: 1)
    .OnComplete(() => SomeMethod());
    
// After the animation completes, wait for 0.5 seconds, then destroy the GameObject
Tween.Scale(transform, endValue: 0, duration: 1, endDelay: 0.5f)
    .OnComplete(() => Destroy(gameObject));

"But wait! There is a memory allocation in the example above" you would say. And you would be right: calling SomeMethod() or Destroy() captures this reference in a closure and allocates heap memory. See how to address this in the zero allocations section.

Delays

Creating delays is by far the most useful feature in game development. Delays in PrimeTween behave like normal tweens and can be used with sequences, coroutines, and async/await methods. All while being completely allocation-free.

csharp
Tween.Delay(duration: 1f, () => Debug.Log("Delay completed"));

Cycles

Animations can be repeated with the help of cycles. To apply cycles to an animation, pass the int cycles and CycleMode cycleMode parameters to a Tween. method. Setting cycles to -1 will repeat the tween indefinitely.

csharp
Tween.PositionY(transform, endValue: 10, duration: 0.5f, cycles: 2, cycleMode: CycleMode.Yoyo);

To apply cycles to a Sequence, use the Sequence.Create(cycles: numCycles, cycleMode: CycleMode.Yoyo) method.

csharp
Sequence.Create(cycles: 2, CycleMode.Yoyo)
    .Chain(Tween.PositionX(transform, 10, duration))
    .Chain(Tween.PositionY(transform, 20, duration));

enum CycleMode

  • Restart (default): restarts the tween from the beginning.
  • Yoyo: animates forth and back, like a yoyo. Easing is the same on the backward cycle.
  • Incremental: at the end of a cycle increments the endValue by the difference between startValue and endValue. For example, if a tween moves position.x from 0 to 1, then after the first cycle, the tween will move the position.x from 1 to 2, and so on.
  • Rewind: rewinds the tween as if time was reversed. Easing is reversed on the backward cycle.

SetRemainingCycles(int cycles)

Sets the number of remaining cycles to an animation. This method modifies the cyclesTotal so that the animation will complete after the number of cycles.

SetRemainingCycles(bool stopAtEndValue)

Stops an animation when it reaches 'startValue' or 'endValue' for the next time.
For example, if you have an infinite animation (cycles == -1) with CycleMode.Yoyo/Rewind, and you wish to stop it when it reaches the 'endValue', then set stopAtEndValue to true. To stop the animation at the 'startValue' set stopAtEndValue to false.

Sequencing tweens

Sequence

There are several sequencing methods in PrimeTween. Let's start with the most common one: grouping tweens in Sequences.

Sequence is a group of tweens, callbacks, and other sequences. Animations in a sequence can overlap, run sequentially or in parallel, or any combination of those. You can control a Sequence the same way as individual tweens, see controlling tweens section.

…

Insert(float atTime, Tween/Sequence animation)

Places animation inside this sequence at the specified time, overlapping with other animations. The total sequence duration is increased if the inserted animation doesn't fit inside the current sequence duration.

Chain(Tween/Sequence animation)

Places animation after all previously added animations in this sequence. Chained animations run sequentially after one another.

Group(Tween/Sequence animation)

Groups animation with the 'previous' animation in this Sequence. The 'previous' animation is the animation used in the preceding Group/Chain/Insert() method call. Grouped animations start at the same time and run in parallel.

Coroutines

Another sequencing method is waiting for animations in coroutines by calling .ToYieldInstruction().

csharp
IEnumerator Coroutine() {
    Tween.PositionX(transform, endValue: 10f, duration: 1.5f);
    yield return Tween.Scale(transform, 2f, 0.5f, startDelay: 1).ToYieldInstruction();
    yield return Tween.Rotation(transform, new Vector3(0f, 0f, 45f), 1f).ToYieldInstruction();
    // Non-allocating alternative to 'yield return new WaitForSeconds(1f)'
    yield return Tween.Delay(1).ToYieldInstruction(); 
    Debug.Log("Sequence completed");
}

Async/await

And the last method is awaiting animations using the async/await pattern. Async/await is a great tool to prevent the callback hell in your code. PrimeTween doesn't use threads, so tweens can be awaited on all platforms, even on WebGL.

csharp
async void AsyncMethod() {
    Tween.PositionX(transform, endValue: 10f, duration: 1.5f);
    await Tween.Scale(transform, endValue: 2f, duration: 0.5f, startDelay: 1);
    await Tween.Rotation(transform, endValue: new Vector3(0f, 0f, 45f), duration: 1f);
    // Non-allocating alternative to 'await Task.Delay(1000)' that doesn't use 'System.Threading'
    // Animations can be awaited on all platforms, even on WebGL
    await Tween.Delay(1); 
    Debug.Log("Sequence completed");
}

While PrimeTween never allocates memory at runtime, the async/await feature in C# is allocating: awaiting an async method allocates a small amount of garbage. Likewise, StartCoroutine() also allocates GC.
For performance-intensive code paths, use Sequence instead of async methods or Coroutines.

SetCancellationToken(CancellationToken cancellationToken)

Use .SetCancellationToken() to stop an animation when a CancellationToken is canceled. Cancellation stops the animation as if Stop() was called and happens on the next PrimeTween update; if the token is already canceled, the animation is stopped immediately. If the animation is awaited with 'await', the 'await' throws an OperationCanceledException when the token is canceled.

To make a Sequence cancellable, call SetCancellationToken() on the Sequence itself instead of its children animations.

csharp
var cancellationTokenSource = new CancellationTokenSource();
Sequence.Create()
    .Chain(Tween.PositionX(transform, endValue: 10f, duration: 1.5f))
    .Chain(Tween.Scale(transform, endValue: 2f, duration: 0.5f))
    .SetCancellationToken(cancellationTokenSource.Token);

// ...
cancellationTokenSource.Cancel(); // stops the animation

Controlling tweens

All static Tween. methods return a Tween struct. While the tween.isAlive you can control it and access its properties such as duration, elapsedTime, progress, interpolationFactor, etc.

After completion, the tween becomes 'dead' and can't be reused. This ensures that completed tweens don't eat computing resources and prevents the common performance pitfalls encountered in other tween libraries.

…

As you can see, there is no way to change the direction of the currently running tween, it can only be stopped and completed. But how to play an animation forward and backward, for example, to show or hide a window? Easy! Just start a new Tween in the desired direction.

csharp
[SerializeField] RectTransform window;

public void SetWindowOpened(bool isOpened) {
    Tween.UIAnchoredPositionY(window, endValue: isOpened ? 0 : -500, duration: 0.5f);
}

In this example, the SetWindowOpened() can be called again while the previous animation is still running. Generally, there is no need to stop the previously running tween in such cases. The new tween will seamlessly start from the current position and overwrite all previously running tweens on the window. Several duplicated tweens are fine, but if your code can potentially create duplicated tweens every frame, then consider stopping the previous tween with the help of tween.Stop() or Tween.StopAll(onTarget: target).

Inspector integration

Inspector integration is the cornerstone of PrimeTween's design. It lets you tweak all animation properties from the Inspector without changing the code. It saves time and gives creative freedom. All animation setting

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C#animationcamera-shakedelayease

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言