DOTween Documentation

repository·develop·Indexed 25 days ago

https://github.com/demigiant/dotween

A high-performance C# animation and tween engine for Unity developed by Daniele Giardini. It features a fluent API for animating properties, creating complex sequences, and implementing physical-style animations like Punch and Shake. The engine includes global configuration settings, capacity management to prevent performance hiccups, and virtual tweens via DOVirtual for non-object-based logic.

Tokens
12.6K
Snippets
4
Records
101
Agent score
81%

What's inside DOTween

  1. Upgrade DOTween to version 1.2.815 or newer

    develop

    To upgrade from versions older than 1.2.815 (or DOTween Pro older than 1.0.405), follow these steps exactly to avoid project errors:

    1. Import the new version: Import the update into the same folder as your existing installation (Plugins/Demigiant), overwriting the old files. You may see errors during this process; ignore them for now.
    2. Restart Unity: Close and reopen Unity and your project. Do not enter Safe Mode; this step is required to resolve the initial errors.
    3. Run Setup: Open the DOTween Utility Panel via Tools > Demigiant > DOTween Utility Panel and click the "Setup DOTween..." button to run the upgrade setup.
    4. Configure Modules: In the Add/Remove Modules panel that appears, activate or deactivate the modules required for Unity systems or external assets (Pro version only).
  2. Get started with DOTween

    develop

    After importing DOTween, follow these steps to begin using it in your project:

    1. Initialize Setup: Open the DOTween Utility Panel from Tools > Demigiant > DOTween Utility Panel and click "Setup DOTween..." to activate/deactivate necessary Modules. You can also use the Preferences tab in this panel to set default settings.
    2. Add Namespace: In your C# scripts, add the following using directive to any class where you intend to use DOTween APIs:
    using DG.Tweening;
  3. Upgrade DOTween from versions older than 1.2.000

    develop

    If you are upgrading from a version older than 1.2.000 (or DOTween Pro older than 1.0.000), follow these steps to avoid errors:

    1. Import the new version into the same folder as the previous version, overwriting the old files. (Note: Errors may appear during this process).
    2. Close and reopen Unity and your project. This step is required to prevent significant issues.
    3. Open the DOTween Utility Panel via Tools > Demigiant > DOTween Utility Panel (if it doesn't open automatically).
    4. Click the "Setup DOTween..." button to run the upgrade setup.
    5. In the Add/Remove Modules panel, activate or deactivate the necessary Modules for Unity systems or external assets (Pro version only).
  4. Set up DOTween in your project

    develop

    After importing DOTween, you must initialize it to activate the required modules and set preferences:

    1. Navigate to Tools > Demigiant > DOTween Utility Panel.
    2. Click the "Setup DOTween..." button.
    3. Use the Add/Remove Modules panel to enable/disable specific Unity system modules.
    4. Use the Preferences Tab within the Utility Panel to configure your default DOTween settings.
  5. Access the DOTween Utility Panel

    develop

    The DOTween Utility Panel is the central hub for managing the library. You can access it via the Unity menu:

    Tools > Demigiant > DOTween Utility Panel

    It provides the following functionality:

    • Setup DOTween...: Runs the module activation/deactivation setup.
    • Add/Remove Modules: Allows you to enable/disable support for specific Unity systems or external assets (Pro version).
    • Preferences Tab: Allows you to configure default settings for DOTween.
  6. Initialize DOTween

    develop

    Call DOTween.Init once before your first tween call to configure global settings. If not called, DOTween will initialize automatically with default options. You can chain SetCapacity to define the initial maximum number of Tweeners and Sequences to avoid performance hiccups caused by automatic capacity increases.

    Note on Recycling: If recycleAllByDefault is set to true, killed tweens are reused from a pool instead of being destroyed. This reduces GC allocations but requires careful management of tween references. To avoid stale references, use the OnKill callback to nullify your references: .OnKill(() => myTweenReference = null)

    DOTween.Init(false, false, LogBehaviour.Default).SetCapacity(100, 20);
  7. Wait for Tweens in Coroutines

    develop

    Use the following WaitFor... extension methods as yield instructions inside Unity Coroutines to wait for specific tween states:

    • yield return myTween.WaitForCompletion();: Waits until killed or complete.
    • yield return myTween.WaitForRewind();: Waits until killed or rewinded.
    • yield return myTween.WaitForKill();: Waits until killed.
    • yield return myTween.WaitForElapsedLoops(int count);: Waits for a specific number of loops.
    • yield return myTween.WaitForPosition(float position);: Waits until a specific position is reached.
    • yield return myTween.WaitForStart();: Waits until the tween starts playing.
    IEnumerator MyCoroutine(Tween myTween) {
        yield return myTween.WaitForStart();
        yield return myTween.WaitForElapsedLoops(2);
        yield return myTween.WaitForCompletion();
    }