Class ScyllaTween
Primary static facade for the Scylla Tween system. Provides factory methods for creating all tween types, a managed update loop, global batch operations, and runtime configuration.
Inherited Members
Namespace: Scylla.Core.Util.Tween
Assembly: ScyllaCore.dll
Syntax
public static class ScyllaTween
Remarks
The tween system supports two modes of operation:
- Managed tweens - registered with TweenManager and updated automatically when Update(float) is called once per frame. Use PlayManaged(ITween) or call SetManaged(bool) before Play() to opt in.
- Manual tweens - the caller is responsible for calling Update(float) each frame. Suitable for tweens embedded inside custom update systems or coroutines.
All tween instances are obtained from type-specific object pools to minimize garbage collection pressure. The pool is initialized lazily on first use, but calling Initialize() at startup preallocates pool entries and avoids the first-use allocation spike. Call Prewarm(int) in addition to preallocate instances into the pool ahead of time.
Global settings such as the default ease type, default duration, and a global time-scale multiplier are stored in TweenSettings and can be changed at any time via SetDefaultEase(EaseType), SetDefaultDuration(float), and SetGlobalTimeScale(float).
For convenience extensions (fluent play helpers, typed casts, loop shorthands, utility
queries) see TweenExtensions.
For Unity component shortcuts (Transform, Material, CanvasGroup, etc.) see the
Tween*Extensions classes in the Extensions subdirectory.
// Fade a CanvasGroup alpha from its current value to 0 over 0.5 seconds.
ScyllaTween.To(() => group.alpha, v => group.alpha = v, 0f, 0.5f)
.SetEase(EaseType.OutQuad)
.OnComplete(() => group.gameObject.SetActive(false))
.PlayManaged();
Value tween with callback (no getter/setter wiring required):
ScyllaTween.Value(0f, 1f, 1f, t => Debug.Log(t)).PlayManaged();
Sequence with staggered tweens:
ScyllaTween.Sequence()
.Append(transform.TweenPosition(target, 0.4f))
.AppendInterval(0.1f)
.AppendCallback(() => Spawn())
.PlayManaged();
Properties
ActiveTweenCount
Gets the number of tweens currently registered with the TweenManager and receiving automatic updates. This count includes tweens in any active state (playing, paused, or in their delay phase).
Declaration
public static int ActiveTweenCount { get; }
Property Value
| Type | Description |
|---|---|
| int | The total number of managed tweens. Returns 0 if no tweens are active. |
See Also
GlobalTimeScale
Gets the current global time-scale multiplier that is applied on top of every
managed tween's individual time-scale during Update(float). The default
value is 1.0 (normal speed).
Declaration
public static float GlobalTimeScale { get; }
Property Value
| Type | Description |
|---|---|
| float | The global time-scale. Always non-negative. |
See Also
Methods
Clear()
Removes all managed tweens and clears all pooled instances without invoking any callbacks. Use this during scene unloads or application teardown when you want a clean slate without triggering any completion or kill logic.
Declaration
public static void Clear()
Remarks
This call clears both TweenManager (stopping automatic updates) and TweenPool (releasing all idle pooled instances). It is more aggressive than KillAll(bool): no callbacks are invoked and the pools are fully drained.
See Also
CompleteAll()
Immediately completes all active managed tweens. Each tween's animated property is set to its end value, its OnComplete(Action) callback is fired, and tweens with AutoKill enabled are then killed and returned to the pool.
Declaration
public static int CompleteAll()
Returns
| Type | Description |
|---|---|
| int | The number of tweens that were completed. Already-completed or killed tweens are not counted. |
See Also
From(Func<float>, Action<float>, float, float)
Creates a float tween that starts at fromValue and
animates toward the current value of getter, which is captured
immediately when this method is called.
Declaration
public static TweenFloat From(Func<float> getter, Action<float> setter, float fromValue, float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<float> | getter | A delegate that returns the value treated as the animation target (end value). It is
invoked immediately at creation time - not at playback start - so the end value is
fixed at the moment this method is called. Must not be |
| Action<float> | setter | A delegate that receives the interpolated value on every update and applies it to the
target. Must not be |
| float | fromValue | The value the animation begins from. The setter is driven toward the end value
(obtained from |
| float | duration | The playback duration in seconds. Values less than zero are clamped to zero. |
Returns
| Type | Description |
|---|---|
| TweenFloat | A TweenFloat instance in the Created state, configured as a From tween. |
Remarks
Unlike To(Func<float>, Action<float>, float, float), which reads the
start value at play time, From snapshots the target end value at creation
time. This is useful when you want to animate into the current state of a property
while overriding the visual starting point - for example, to implement an intro
animation that "arrives" at the property's current value.
See Also
From(Func<Color>, Action<Color>, Color, float)
Creates a UnityEngine.Color tween that starts at fromValue and
animates toward the current value of getter, which is captured
immediately when this method is called.
Declaration
public static TweenColor From(Func<Color> getter, Action<Color> setter, Color fromValue, float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Color> | getter | A delegate that returns the UnityEngine.Color treated as the animation target.
Invoked immediately at creation time to snapshot the end value. Must not be
|
| Action<Color> | setter | A delegate that receives the interpolated UnityEngine.Color on every update and
applies it to the target. Must not be |
| Color | fromValue | The UnityEngine.Color the animation begins from. |
| float | duration | The playback duration in seconds. Values less than zero are clamped to zero. |
Returns
| Type | Description |
|---|---|
| TweenColor | A TweenColor instance in the Created state, configured as a From tween. |
See Also
From(Func<Vector3>, Action<Vector3>, Vector3, float)
Creates a UnityEngine.Vector3 tween that starts at fromValue
and animates toward the current value of getter, which is
captured immediately when this method is called.
Declaration
public static TweenVector3 From(Func<Vector3> getter, Action<Vector3> setter, Vector3 fromValue, float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Vector3> | getter | A delegate that returns the UnityEngine.Vector3 treated as the animation target.
Invoked immediately at creation time to snapshot the end value. Must not be
|
| Action<Vector3> | setter | A delegate that receives the interpolated UnityEngine.Vector3 on every update and
applies it to the target. Must not be |
| Vector3 | fromValue | The UnityEngine.Vector3 the animation begins from. |
| float | duration | The playback duration in seconds. Values less than zero are clamped to zero. |
Returns
| Type | Description |
|---|---|
| TweenVector3 | A TweenVector3 instance in the Created state, configured as a From tween. |
See Also
GetTween(TweenID)
Looks up an active managed tween by its unique TweenID.
Declaration
public static ITween GetTween(TweenID id)
Parameters
| Type | Name | Description |
|---|---|---|
| TweenID | id | The TweenID to search for. Obtain this value from ID after creating a tween. |
Returns
| Type | Description |
|---|---|
| ITween | The ITween registered under |
Remarks
Only managed tweens are tracked by ID. Manual tweens (those not registered with TweenManager) cannot be retrieved via this method; callers must hold a direct reference to them.
See Also
Initialize()
Initializes the tween object pools with the default capacities specified in TweenSettings. Call this during application startup to preallocate pool entries and avoid allocation spikes the first time tweens are created.
Declaration
public static void Initialize()
Remarks
If the pools have already been initialized this call is a no-op. The pools are also initialized automatically on first use if this method is never called, so calling it is optional but recommended for performance-critical applications.
See Also
Initialize(int, int)
Initializes the tween object pools with custom capacity settings. Each concrete tween type (TweenFloat, TweenVector3, TweenColor, etc.) gets its own pool sized according to these parameters. The sequence pool is initialized with half the supplied capacity and max-size values.
Declaration
public static void Initialize(int poolCapacity, int poolMaxSize)
Parameters
| Type | Name | Description |
|---|---|---|
| int | poolCapacity | The initial number of pre-allocated instances per tween-type pool. Higher values reduce early-game allocation at the cost of startup memory. Must be at least 1. |
| int | poolMaxSize | The maximum number of idle instances each pool is allowed to retain. Instances returned to a full pool are discarded rather than pooled. Must be at least 1. |
Remarks
If the pools have already been initialized this call is a no-op. Passing values here overrides DefaultPoolCapacity and DefaultPoolMaxSize for the current session.
See Also
IsTweening(object)
Determines whether the given object has at least one active managed tween targeting it. A tween is considered active if it is playing, in its delay phase, or paused.
Declaration
public static bool IsTweening(object target)
Parameters
| Type | Name | Description |
|---|---|---|
| object | target | The object to check. This is matched against the target set via
SetTarget(object) (called automatically by the
|
Returns
| Type | Description |
|---|---|
| bool |
|
See Also
KillAll(bool)
Kills all tweens currently managed by TweenManager, optionally completing them first so that every animated property snaps to its end value before being released.
Declaration
public static int KillAll(bool complete = false)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | complete | When |
Returns
| Type | Description |
|---|---|
| int | The number of managed tweens that were killed. Returns 0 if no tweens were active. |
See Also
KillTweensOf(object, bool)
Kills all managed tweens whose Target matches
target, optionally completing them first.
Declaration
public static int KillTweensOf(object target, bool complete = false)
Parameters
| Type | Name | Description |
|---|---|---|
| object | target | The object whose tweens should be killed. This is matched against the target set via
SetTarget(object) (called automatically by the
|
| bool | complete | When |
Returns
| Type | Description |
|---|---|
| int | The number of tweens killed. Returns 0 if the target has no active managed tweens. |
See Also
PauseAll()
Pauses all currently playing managed tweens, suspending their progress until ResumeAll() is called. Tweens already paused or in any other non-playing state are not affected.
Declaration
public static int PauseAll()
Returns
| Type | Description |
|---|---|
| int | The number of tweens that were actively playing and were therefore paused. Tweens already paused are not counted. |
See Also
Prewarm(int)
Prewarms each tween-type pool by creating count idle instances and
placing them into the pool immediately. This eliminates object-creation cost during the
first burst of tween activity (e.g., at a scene transition or UI animation).
Declaration
public static void Prewarm(int count)
Parameters
| Type | Name | Description |
|---|---|---|
| int | count | The number of instances to prewarm per tween-type pool. The sequence pool is prewarmed with half this value. A value of 0 or less is effectively a no-op. |
Remarks
The pools must be initialized before calling this method. If they have not been initialized, Initialize() is called automatically first.
See Also
ResetSettings()
Resets all global tween settings to their factory defaults:
- GlobalTimeScale = 1.0
- DefaultEaseType = OutQuad
- DefaultDuration = 0.3 seconds
- DefaultAutoKill = true
- DefaultPoolCapacity = 64
- DefaultPoolMaxSize = 500
This does not affect any tweens that are already in progress.
Declaration
public static void ResetSettings()
See Also
ResumeAll()
Resumes all managed tweens that are currently in the paused state, returning them to their previous playing or delay-countdown state. Tweens in other states are not affected.
Declaration
public static int ResumeAll()
Returns
| Type | Description |
|---|---|
| int | The number of tweens that were paused and were therefore resumed. Tweens already playing are not counted. |
See Also
Sequence()
Creates and returns a new empty TweenSequence sourced from the internal pool. A sequence allows multiple tweens and callbacks to be composed into a single timeline.
Declaration
public static TweenSequence Sequence()
Returns
| Type | Description |
|---|---|
| TweenSequence | A TweenSequence instance in the Created state with no items. |
Remarks
Build the timeline by chaining calls to Append(ITween), Join(ITween), Insert(float, ITween), AppendInterval(float), AppendCallback(Action), or Prepend(ITween), then call Play() or PlayManaged(ITween) to start it.
Individual tweens added to a sequence should not be played independently; the sequence drives their playback. Each child tween retains its own ease, duration, and looping settings, but the sequence's time-scale and delay apply at the sequence level.
ScyllaTween.Sequence()
.Append(transform.TweenPosition(new Vector3(5f, 0f, 0f), 0.5f))
.Join(transform.TweenScale(Vector3.one * 1.5f, 0.5f))
.AppendInterval(0.2f)
.AppendCallback(() => Debug.Log("Arrived!"))
.SetLoops(3, LoopType.Yoyo)
.PlayManaged();
See Also
SetDefaultDuration(float)
Sets the default playback duration (in seconds) used for newly created tweens when no explicit duration is provided. This overrides DefaultDuration for the remainder of the session or until ResetSettings() is called.
Declaration
public static void SetDefaultDuration(float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| float | duration | The new default duration in seconds. Must be zero or positive; negative values throw an ArgumentOutOfRangeException inside TweenSettings. |
Remarks
The factory default is 0.3 seconds. Changing this setting does not affect
tweens that have already been created.
See Also
SetDefaultEase(EaseType)
Sets the default EaseType applied to newly created tweens. This overrides the value stored in DefaultEaseType for the remainder of the session or until ResetSettings() is called.
Declaration
public static void SetDefaultEase(EaseType easeType)
Parameters
| Type | Name | Description |
|---|---|---|
| EaseType | easeType | The easing function to use by default. Individual tweens can still override this per-instance via SetEase(EaseType). |
Remarks
The factory default is OutQuad. Changing this setting does not affect tweens that have already been created.
See Also
SetGlobalTimeScale(float)
Sets the global time-scale multiplier applied to every managed tween during
Update(float). A value of 1.0 is normal speed, 0.5 is half
speed (slow-motion), and 2.0 is double speed. A value of 0.0 effectively
pauses all managed tweens without changing their individual paused states.
Declaration
public static void SetGlobalTimeScale(float timeScale)
Parameters
| Type | Name | Description |
|---|---|---|
| float | timeScale | The time-scale multiplier. Must be zero or positive; negative values throw an ArgumentOutOfRangeException inside TweenSettings. |
Remarks
Manual tweens are not affected by the global time-scale. Each tween also
has an individual time-scale settable via SetTimeScale(float); the
effective delta for a managed tween is
deltaTime * tween.TimeScale * GlobalTimeScale.
This value is stored in GlobalTimeScale and persists until explicitly changed or ResetSettings() is called.
See Also
To(Func<float>, Action<float>, float, float)
Creates a tween that interpolates a float value from its current value (read
via getter at the moment the tween starts playing) to
endValue over duration seconds.
Declaration
public static TweenFloat To(Func<float> getter, Action<float> setter, float endValue, float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<float> | getter | A delegate that returns the current value of the property being animated. This is
called once when the tween first begins playing (after any configured delay) to
establish the start value. Must not be |
| Action<float> | setter | A delegate that receives the interpolated value on every update and applies it to the
target property. Must not be |
| float | endValue | The target value the tween will reach at |
| float | duration | The playback duration in seconds. Values less than zero are clamped to zero, which causes the tween to complete in a single frame. |
Returns
| Type | Description |
|---|---|
| TweenFloat | A TweenFloat instance sourced from the internal pool. The tween is in the Created state; call Play() or PlayManaged(ITween) to start it. |
Remarks
The returned tween uses the ease type configured in DefaultEaseType (OutQuad by default). Override it by calling SetEase(EaseType) before playing.
See Also
To(Func<Color>, Action<Color>, Color, float)
Creates a tween that interpolates a UnityEngine.Color value from its current value
(read via getter at playback start) to endValue
over duration seconds.
Declaration
public static TweenColor To(Func<Color> getter, Action<Color> setter, Color endValue, float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Color> | getter | A delegate that returns the current UnityEngine.Color being animated. Called once
when the tween first begins playing to capture the start value. Must not be
|
| Action<Color> | setter | A delegate that receives the interpolated UnityEngine.Color on every update and
applies it to the target. Must not be |
| Color | endValue | The target UnityEngine.Color the tween will reach at |
| float | duration | The playback duration in seconds. Values less than zero are clamped to zero. |
Returns
| Type | Description |
|---|---|
| TweenColor | A TweenColor instance in the Created state. |
See Also
To(Func<Quaternion>, Action<Quaternion>, Quaternion, float)
Creates a tween that interpolates a UnityEngine.Quaternion value from its current
value (read via getter at playback start) to
endValue over duration seconds using spherical
linear interpolation (Slerp).
Declaration
public static TweenQuaternion To(Func<Quaternion> getter, Action<Quaternion> setter, Quaternion endValue, float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Quaternion> | getter | A delegate that returns the current UnityEngine.Quaternion being animated. Called
once when the tween first begins playing to capture the start value. Must not be
|
| Action<Quaternion> | setter | A delegate that receives the interpolated UnityEngine.Quaternion on every update
and applies it to the target. Must not be |
| Quaternion | endValue | The target UnityEngine.Quaternion the tween will reach at |
| float | duration | The playback duration in seconds. Values less than zero are clamped to zero. |
Returns
| Type | Description |
|---|---|
| TweenQuaternion | A TweenQuaternion instance in the Created state. |
Remarks
Quaternion interpolation uses Slerp rather than Lerp, ensuring smooth constant-angular- speed rotation regardless of the angular distance between start and end orientations.
See Also
To(Func<Vector2>, Action<Vector2>, Vector2, float)
Creates a tween that interpolates a UnityEngine.Vector2 value from its current
value (read via getter at playback start) to
endValue over duration seconds.
Declaration
public static TweenVector2 To(Func<Vector2> getter, Action<Vector2> setter, Vector2 endValue, float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Vector2> | getter | A delegate that returns the current UnityEngine.Vector2 being animated. Called once
when the tween first begins playing to capture the start value. Must not be
|
| Action<Vector2> | setter | A delegate that receives the interpolated UnityEngine.Vector2 on every update and
applies it to the target. Must not be |
| Vector2 | endValue | The target UnityEngine.Vector2 the tween will reach at |
| float | duration | The playback duration in seconds. Values less than zero are clamped to zero. |
Returns
| Type | Description |
|---|---|
| TweenVector2 | A TweenVector2 instance in the Created state. |
See Also
To(Func<Vector3>, Action<Vector3>, Vector3, float)
Creates a tween that interpolates a UnityEngine.Vector3 value from its current
value (read via getter at playback start) to
endValue over duration seconds.
Declaration
public static TweenVector3 To(Func<Vector3> getter, Action<Vector3> setter, Vector3 endValue, float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Vector3> | getter | A delegate that returns the current UnityEngine.Vector3 being animated. Called once
when the tween first begins playing to capture the start value. Must not be
|
| Action<Vector3> | setter | A delegate that receives the interpolated UnityEngine.Vector3 on every update and
applies it to the target. Must not be |
| Vector3 | endValue | The target UnityEngine.Vector3 the tween will reach at |
| float | duration | The playback duration in seconds. Values less than zero are clamped to zero. |
Returns
| Type | Description |
|---|---|
| TweenVector3 | A TweenVector3 instance in the Created state. |
See Also
To(Func<Vector4>, Action<Vector4>, Vector4, float)
Creates a tween that interpolates a UnityEngine.Vector4 value from its current
value (read via getter at playback start) to
endValue over duration seconds.
Declaration
public static TweenVector4 To(Func<Vector4> getter, Action<Vector4> setter, Vector4 endValue, float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Vector4> | getter | A delegate that returns the current UnityEngine.Vector4 being animated. Called once
when the tween first begins playing to capture the start value. Must not be
|
| Action<Vector4> | setter | A delegate that receives the interpolated UnityEngine.Vector4 on every update and
applies it to the target. Must not be |
| Vector4 | endValue | The target UnityEngine.Vector4 the tween will reach at |
| float | duration | The playback duration in seconds. Values less than zero are clamped to zero. |
Returns
| Type | Description |
|---|---|
| TweenVector4 | A TweenVector4 instance in the Created state. |
See Also
Update(float)
Advances all currently managed tweens by deltaTime seconds. This
method must be called once per frame by the host update system (e.g., a
MonoBehaviour.Update or LateUpdate method) to drive managed tween
playback. Manual tweens are not affected.
Declaration
public static void Update(float deltaTime)
Parameters
| Type | Name | Description |
|---|---|---|
| float | deltaTime | The time elapsed since the last frame in seconds. Typically
|
Remarks
Tweens whose target is a destroyed UnityEngine.Object are
automatically culled during this update. Tweens that complete and have
AutoKill set to true (the default) are also removed
and returned to the pool.
See Also
Value(float, float, float, Action<float>)
Creates a self-contained float tween that animates from from
to to and delivers each interpolated value to
onUpdate on every frame.
Declaration
public static TweenFloat Value(float from, float to, float duration, Action<float> onUpdate)
Parameters
| Type | Name | Description |
|---|---|---|
| float | from | The starting value of the animation range. |
| float | to | The ending value of the animation range. |
| float | duration | The playback duration in seconds. Values less than zero are clamped to zero. |
| Action<float> | onUpdate | A callback invoked on every update with the current interpolated value. The callback
is responsible for applying the value to whatever it needs to animate. A |
Returns
| Type | Description |
|---|---|
| TweenFloat | A TweenFloat instance in the Created state. |
Remarks
Unlike To(Func<float>, Action<float>, float, float), this overload
does not require wiring up a getter and setter to a specific property. The current
value is tracked internally and forwarded to onUpdate each
frame. This is useful for driving custom logic (e.g., spawning particles at
arbitrary positions, procedural animation) where no single property is the
animation target.
// Drive an arbitrary fill amount from 0 to 1 over two seconds.
ScyllaTween.Value(0f, 1f, 2f, t => slider.value = t).PlayManaged();
See Also
Value(Color, Color, float, Action<Color>)
Creates a self-contained UnityEngine.Color tween that animates from
from to to and delivers each interpolated
value to onUpdate on every frame.
Declaration
public static TweenColor Value(Color from, Color to, float duration, Action<Color> onUpdate)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | from | The starting UnityEngine.Color of the animation range. |
| Color | to | The ending UnityEngine.Color of the animation range. |
| float | duration | The playback duration in seconds. Values less than zero are clamped to zero. |
| Action<Color> | onUpdate | A callback invoked on every update with the current interpolated UnityEngine.Color.
A |
Returns
| Type | Description |
|---|---|
| TweenColor | A TweenColor instance in the Created state. |
Remarks
The current color is tracked internally; the caller receives it only via
onUpdate without needing to expose a property getter/setter.
See Also
Value(Vector3, Vector3, float, Action<Vector3>)
Creates a self-contained UnityEngine.Vector3 tween that animates from
from to to and delivers each interpolated
value to onUpdate on every frame.
Declaration
public static TweenVector3 Value(Vector3 from, Vector3 to, float duration, Action<Vector3> onUpdate)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | from | The starting UnityEngine.Vector3 of the animation range. |
| Vector3 | to | The ending UnityEngine.Vector3 of the animation range. |
| float | duration | The playback duration in seconds. Values less than zero are clamped to zero. |
| Action<Vector3> | onUpdate | A callback invoked on every update with the current interpolated
UnityEngine.Vector3. A |
Returns
| Type | Description |
|---|---|
| TweenVector3 | A TweenVector3 instance in the Created state. |
Remarks
The current value is tracked internally; the caller receives it only via
onUpdate without needing to expose a property getter/setter.