Class TweenQuaternion
A performance-optimized, sealed tween implementation that interpolates UnityEngine.Quaternion rotations using either spherical linear interpolation (Slerp, default) or normalized linear interpolation (Nlerp).
Implements
Inherited Members
Namespace: Scylla.Core.Util.Tween
Assembly: ScyllaCore.dll
Syntax
public sealed class TweenQuaternion : TweenBase, ITween
Remarks
Interpolation modes:
-
Slerp (default): Uses
Quaternion(Quaternion, Quaternion, float)
which internally calls
Quaternion.SlerpUnclamped. This guarantees constant angular velocity and takes the shortest rotational path. It is the correct choice for most gameplay rotation animations. The unclamped variant is used so that elastic and back easing can produce overshoot. -
Nlerp (linear): Enabled via SetLinearInterpolation(bool).
Uses QuaternionLinear(Quaternion, Quaternion, float)
which internally calls
Quaternion.LerpUnclamped. Faster to compute than Slerp and suitable for small-angle or UI animations, but angular velocity is not constant over the arc for large rotations.
Euler-angle convenience overloads:
InitializeEuler(Func<Quaternion>, Action<Quaternion>, Vector3, float)
and SetFromEuler(Vector3) / SetEndValueEuler(Vector3) accept Euler
angles in degrees and convert them to UnityEngine.Quaternion via
Quaternion.Euler. Internally the tween always works in quaternion space.
Vs. TweenVector3 on Euler: For rotation animations, always prefer TweenQuaternion over TweenVector3 on Euler angles. Quaternion Slerp avoids gimbal lock, handles wrap-around correctly, and takes the shortest angular path. Linear interpolation of Euler angles can produce unexpected spinning behavior when angles cross the 180°/360° boundary.
To vs. From: By default the start value is captured from the getter when
Play() is called. Call SetFrom(Quaternion) or
SetFromEuler(Vector3) before Play to pin an explicit starting rotation.
Incremental loops: Incremental is NOT supported by this type and currently behaves identically to Restart: ApplyValue(float) always interpolates between the fixed start and end rotations, so no per-iteration accumulation occurs. The numeric tween types (float, Vector2/3/4) accumulate via dedicated incremental lerp helpers, which have no quaternion equivalent. Do not rely on incremental accumulation for rotation; drive a continuous spin with a looping numeric-angle tween or a large end rotation.
Pool contract: Reset() resets both quaternion fields to
UnityEngine.Quaternion.identity and clears the getter, setter, _usesFrom,
and _useLinearInterpolation flags so the instance can be safely returned to
TweenPool.
Constructors
TweenQuaternion()
Creates a new, unconfigured TweenQuaternion instance.
Declaration
public TweenQuaternion()
Remarks
Used by TweenPool when pre-allocating instances. Call Initialize(Func<Quaternion>, Action<Quaternion>, Quaternion, float) or InitializeEuler(Func<Quaternion>, Action<Quaternion>, Vector3, float) before playing.
TweenQuaternion(Func<Quaternion>, Action<Quaternion>, Quaternion, float)
Creates a fully configured TweenQuaternion and immediately calls Initialize(Func<Quaternion>, Action<Quaternion>, Quaternion, float).
Declaration
public TweenQuaternion(Func<Quaternion> getter, Action<Quaternion> setter, Quaternion endValue, float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Quaternion> | getter | A delegate that reads the current UnityEngine.Quaternion rotation of the target
property. Must not be |
| Action<Quaternion> | setter | A delegate that writes the interpolated UnityEngine.Quaternion to the target
property each frame. Must not be |
| Quaternion | endValue | The target UnityEngine.Quaternion rotation to animate toward. |
| float | duration | Total playback time in seconds. Negative values are clamped to zero. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
Properties
EndValue
Gets the UnityEngine.Quaternion target rotation toward which the tween interpolates.
Declaration
public Quaternion EndValue { get; }
Property Value
| Type | Description |
|---|---|
| Quaternion | The end rotation supplied to Initialize(Func<Quaternion>, Action<Quaternion>, Quaternion, float) or converted from Euler angles by InitializeEuler(Func<Quaternion>, Action<Quaternion>, Vector3, float). |
StartValue
Gets the UnityEngine.Quaternion rotation from which the tween interpolates.
Declaration
public Quaternion StartValue { get; }
Property Value
| Type | Description |
|---|---|
| Quaternion | The start rotation pinned at play time, or the value passed to SetFrom(Quaternion) or SetFromEuler(Vector3). Returns UnityEngine.Quaternion.identity before the tween has started and no explicit start value has been set. |
Methods
ApplyValue(float)
Writes the interpolated value to the target property at the given eased progress. Must be implemented by derived classes to perform type-specific interpolation.
Declaration
protected override void ApplyValue(float easedProgress)
Parameters
| Type | Name | Description |
|---|---|---|
| float | easedProgress | The eased (and Yoyo-corrected) progress value computed by EasedProgress.
This value is intentionally unclamped; elastic and back easing can produce values below
|
Overrides
Remarks
On the first call when Progress is at or below zero and no start value has
been pinned, the getter is invoked to capture the current rotation. The interpolation
method is then selected based on _useLinearInterpolation: Slerp (via
Quaternion(Quaternion, Quaternion, float)) or Nlerp (via
QuaternionLinear(Quaternion, Quaternion, float)). The
unclamped variants are used to support overshoot easing.
CaptureStartValue()
Called once during Play() (for new or restarted tweens) to snapshot the current value of the target property as the tween's start value, without applying any change.
Declaration
protected override void CaptureStartValue()
Overrides
Remarks
The base implementation is empty. Derived classes override this to read their getter
delegate and store the result in their start-value field, but only when a start value
has not already been pinned via a SetFrom call. This approach ensures that
the start value reflects the live property value at the moment play begins, not at
the moment the tween was created.
Initialize(Func<Quaternion>, Action<Quaternion>, Quaternion, float)
Configures this tween with all required parameters for UnityEngine.Quaternion interpolation.
Defaults to Slerp mode and resets _usesFrom so the start value is captured
from the getter at play time.
Declaration
public TweenQuaternion Initialize(Func<Quaternion> getter, Action<Quaternion> setter, Quaternion endValue, float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Quaternion> | getter | A delegate that reads the current UnityEngine.Quaternion rotation of the target
property each frame. Must not be |
| Action<Quaternion> | setter | A delegate that writes the interpolated UnityEngine.Quaternion to the target
property each frame. Must not be |
| Quaternion | endValue | The UnityEngine.Quaternion rotation to animate toward. Captured by value; subsequent changes to the source variable are not reflected unless this method is called again or SetEndValue(Quaternion) is used. |
| float | duration | Playback duration in seconds. Clamped to zero; a value of zero produces an instant-complete tween on the first update frame. |
Returns
| Type | Description |
|---|---|
| TweenQuaternion | This tween instance for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
InitializeEuler(Func<Quaternion>, Action<Quaternion>, Vector3, float)
Configures this tween using Euler angles (in degrees) for the target end rotation,
converting them to a UnityEngine.Quaternion via Quaternion.Euler.
Equivalent to calling
Initialize(Func<Quaternion>, Action<Quaternion>, Quaternion, float)
with Quaternion.Euler(endEuler).
Declaration
public TweenQuaternion InitializeEuler(Func<Quaternion> getter, Action<Quaternion> setter, Vector3 endEuler, float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Quaternion> | getter | A delegate that reads the current UnityEngine.Quaternion rotation. Must not be |
| Action<Quaternion> | setter | A delegate that writes the interpolated rotation to the target property. Must not be |
| Vector3 | endEuler | The target rotation expressed as Euler angles in degrees (X, Y, Z). The conversion is performed once at this call; the Euler values are not re-evaluated during playback. |
| float | duration | Playback duration in seconds. Negative values are clamped to zero. |
Returns
| Type | Description |
|---|---|
| TweenQuaternion | This tween instance for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
PrepareIncrementalLoop()
Called at the end of each Incremental loop iteration to allow derived classes to update internal state before the next iteration begins.
Declaration
protected override void PrepareIncrementalLoop()
Overrides
Remarks
The base implementation is empty. Derived classes that support incremental looping (e.g., TweenFloat, TweenVector3) override this to capture the current property value as the new start point, so each loop iteration adds the change amount on top of the previous iteration's result.
Reset()
Resets all tween state back to initial defaults, preparing the instance for reuse from a pool.
Declaration
public override void Reset()
Overrides
Remarks
Clears all callbacks, resets timing values, generates a new TweenID,
and sets State back to Created. This is
called automatically by the tween pool (TweenPool) before returning an
instance to a caller. Derived classes that override this method must call the base
implementation.
SetEndValue(Quaternion)
Updates the UnityEngine.Quaternion end rotation that the tween animates toward.
Declaration
public TweenQuaternion SetEndValue(Quaternion endValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Quaternion | endValue | The new target UnityEngine.Quaternion rotation. |
Returns
| Type | Description |
|---|---|
| TweenQuaternion | This tween instance for method chaining. |
Remarks
Safe to call while the tween is playing. The change takes effect on the next Update(float) call.
SetEndValueEuler(Vector3)
Updates the end rotation using Euler angles in degrees, converting them to a
UnityEngine.Quaternion via Quaternion.Euler.
Declaration
public TweenQuaternion SetEndValueEuler(Vector3 endEuler)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | endEuler | The new target rotation in Euler angles (degrees). Converted immediately; the Euler values are not stored or re-evaluated during playback. |
Returns
| Type | Description |
|---|---|
| TweenQuaternion | This tween instance for method chaining. |
SetFrom(Quaternion)
Pins an explicit start rotation, converting this into a "From" tween that begins
at fromValue and animates toward the configured end rotation.
Declaration
public TweenQuaternion SetFrom(Quaternion fromValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Quaternion | fromValue | The UnityEngine.Quaternion from which interpolation begins. Overrides automatic start-value capture at play time. |
Returns
| Type | Description |
|---|---|
| TweenQuaternion | This tween instance for method chaining. |
SetFromEuler(Vector3)
Pins an explicit start rotation specified as Euler angles (in degrees), converting
them to a UnityEngine.Quaternion via Quaternion.Euler.
Declaration
public TweenQuaternion SetFromEuler(Vector3 fromEuler)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | fromEuler | The start rotation in Euler angles (degrees). The conversion is performed once here and is not re-evaluated during playback. |
Returns
| Type | Description |
|---|---|
| TweenQuaternion | This tween instance for method chaining. |
SetLinearInterpolation(bool)
Chooses between spherical interpolation (Slerp, default) and normalized linear interpolation (Nlerp) for this tween.
Declaration
public TweenQuaternion SetLinearInterpolation(bool useLinear)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | useLinear |
|
Returns
| Type | Description |
|---|---|
| TweenQuaternion | This tween instance for method chaining. |