Class TweenVector3
A performance-optimized, sealed tween implementation that interpolates UnityEngine.Vector3 values component-by-component. The most commonly used tween type for 3D game development; suitable for animating world positions, local positions, Euler angles (as raw Vector3), scale, and any other three-component float property.
Implements
Inherited Members
Namespace: Scylla.Core.Util.Tween
Assembly: ScyllaCore.dll
Syntax
public sealed class TweenVector3 : TweenBase, ITween
Remarks
Interpolation: Uses Vector3(Vector3, Vector3, float) for standard playback and Vector3Incremental(Vector3, Vector3, float, int) when LoopType is Incremental. Both functions perform unclamped per-component linear math so that elastic and back easing produce the correct overshoot on all three axes.
Rotation note: When animating Euler angles, consider using
TweenQuaternion instead, which uses spherical interpolation
(Quaternion.SlerpUnclamped) to avoid gimbal lock and take the shortest
rotational path. TweenVector3 on Euler angles performs linear interpolation
per axis, which can produce unexpected results for large rotations.
Change value: The internal _changeValue field is precomputed as
endValue - startValue and is used only during incremental loops to avoid
repeated subtraction in the hot path.
To vs. From: By default the start value is captured from the getter when
Play() is called. Call SetFrom(Vector3) before
Play to pin an explicit starting UnityEngine.Vector3.
Typical usage via the ScyllaTween factory:
<pre><code class="lang-csharp">var tween = ScyllaTween.To(
() => transform.position,
v => transform.position = v,
targetPosition,
1.5f)
.SetEase(EaseType.OutCubic) .SetManaged(true) .Play();
Pool contract: Reset() zeroes all value fields and clears the getter and setter delegates so the instance can be safely returned to TweenPool.
Constructors
TweenVector3()
Creates a new, unconfigured TweenVector3 instance.
Declaration
public TweenVector3()
Remarks
Used by TweenPool when pre-allocating instances. Call Initialize(Func<Vector3>, Action<Vector3>, Vector3, float) before playing.
TweenVector3(Func<Vector3>, Action<Vector3>, Vector3, float)
Creates a fully configured TweenVector3 and immediately calls Initialize(Func<Vector3>, Action<Vector3>, Vector3, float).
Declaration
public TweenVector3(Func<Vector3> getter, Action<Vector3> setter, Vector3 endValue, float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Vector3> | getter | A delegate that reads the current UnityEngine.Vector3 of the target property.
Must not be |
| Action<Vector3> | setter | A delegate that writes the interpolated UnityEngine.Vector3 to the target property
each frame. Must not be |
| Vector3 | endValue | The target UnityEngine.Vector3 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.Vector3 target value toward which the tween interpolates.
Declaration
public Vector3 EndValue { get; }
Property Value
| Type | Description |
|---|---|
| Vector3 | The end value supplied to Initialize(Func<Vector3>, Action<Vector3>, Vector3, float). |
StartValue
Gets the UnityEngine.Vector3 value from which the tween interpolates.
Declaration
public Vector3 StartValue { get; }
Property Value
| Type | Description |
|---|---|
| Vector3 | The start value pinned at play time, or the value passed to SetFrom(Vector3). Returns UnityEngine.Vector3.zero 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, the result stored as _startValue, and
_changeValue is computed as _endValue - _startValue. For subsequent
frames, either Vector3(Vector3, Vector3, float) (Restart/Yoyo) or
Vector3Incremental(Vector3, Vector3, float, int) (Incremental) is used and the result
written via the setter.
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<Vector3>, Action<Vector3>, Vector3, float)
Configures this tween with all required parameters for UnityEngine.Vector3 interpolation.
Resets the _usesFrom flag so the start value is captured from the getter at
play time (standard "To" tween behavior). Call SetFrom(Vector3) afterward to
override with an explicit starting value.
Declaration
public TweenVector3 Initialize(Func<Vector3> getter, Action<Vector3> setter, Vector3 endValue, float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Vector3> | getter | A delegate that reads the current UnityEngine.Vector3 of the target property each
frame. Must not be |
| Action<Vector3> | setter | A delegate that writes the interpolated UnityEngine.Vector3 to the target property
each frame. Must not be |
| Vector3 | endValue | The UnityEngine.Vector3 to animate toward. Captured by value; subsequent changes to the source variable are not reflected unless this method is called again or SetEndValue(Vector3) 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 |
|---|---|
| TweenVector3 | 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(Vector3)
Updates the UnityEngine.Vector3 end value that the tween animates toward.
Declaration
public TweenVector3 SetEndValue(Vector3 endValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | endValue | The new target UnityEngine.Vector3 value. |
Returns
| Type | Description |
|---|---|
| TweenVector3 | 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.
SetFrom(Vector3)
Pins an explicit start value, converting this into a "From" tween that begins at
fromValue and animates toward the configured end value.
Declaration
public TweenVector3 SetFrom(Vector3 fromValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | fromValue | The UnityEngine.Vector3 from which interpolation begins. Overrides automatic start-value capture at play time. |
Returns
| Type | Description |
|---|---|
| TweenVector3 | This tween instance for method chaining. |