C#Beta
Custom definitions
A custom definition animates storage the catalog doesn’t cover. Pass delegates to Tweens.Property, or derive from TweenDefinition<TTarget, TValue> for setup and cleanup around each playback; both start like any built-in definition. Custom properties walks through both.
// Tweens a camera's zoom as one number, keeping X and Y equal.var zoom = new Tweens.Property<Camera2D, float>( target => target.Zoom.X, (target, value) => target.Zoom = new Vector2(value, value), Interpolators.Float, to: 2, duration: 0.5, ease: InOut.SmootherStep);
camera.Tween(zoom);// Tweens a camera's zoom as one number, keeping X and Y equal.public sealed class UniformZoomTween : TweenDefinition<Camera2D, float>{ protected override float Read(Camera2D target) => target.Zoom.X; protected override void Write(Camera2D target, float value) => target.Zoom = new Vector2(value, value); protected override float Interpolate(float from, float to, float weight) => Interpolators.Float(from, to, weight);}camera.Tween(new UniformZoomTween { To = 2, Duration = 0.5, Ease = InOut.SmootherStep });Delegates
Section titled “Delegates”| Constructor | Arguments |
|---|---|
new Tweens.Property<TTarget, TValue>(getter, setter, interpolate, to, duration, ease, delay) |
The property operations, then the optional endpoint and timing |
new PropertyTween<TTarget, TValue>(getter, setter, interpolate) |
The same operations, as a mutable class definition |
interpolate takes (from, to, weight); pass one of the Interpolators. Captured objects stay shared between playbacks.
Members to override
Section titled “Members to override”TweenDefinition<TTarget, TValue> is abstract; TTarget is a class and TValue a struct. Its public members, from From to OnFinally, match the built-in definitions. These are all protected:
| Method | Returns | Purpose |
|---|---|---|
Read(target) |
TValue |
Read the current value. Required |
Write(target, value) |
void |
Write a value. Required |
Interpolate(from, to, weight) |
TValue |
Blend two values; weight leaves 0 to 1 when an ease overshoots. Required |
Prepare(target) |
void |
Set up this playback’s bindings |
Restore(target, initial) |
void |
Undo the tween at a non-retaining end; writes initial unless overridden |
Release() |
void |
Free this playback’s resources |
ReadsWrittenValue |
bool |
Whether Read returns what Write stored; true unless overridden |
Binding lifecycle
Section titled “Binding lifecycle”- Copy. Each start works on a private, shallow copy of the definition, so per-playback state belongs in its fields. Reference-valued fields stay shared.
Prepareruns on that copy at activation, before the first read.Readcaptures the start value.InterpolateandWriterun on every update.Restoreruns at a natural end whose fill doesn’t keep the final value. It can writeinitialback, or remove an override instead.Releaseruns after the ending callbacks, and also after a failedPrepare. Release only what this copy owns.
Interpolators
Section titled “Interpolators”Interpolators has one static method per built-in value type, each taking (from, to, weight). Pass one as the interpolate argument, or call it from your own Interpolate.
| Method | Returns | Purpose |
|---|---|---|
Float, Double |
float, double |
Linear blend; overshoot passes through |
Int |
int |
Rounds half away from zero; overshoot saturates at the int limits |
Vector2, Vector3, Vector4, Color, Rect2 |
the same type | Component-wise linear blend |
Quaternion |
Quaternion |
Shortest-path spherical blend; endpoints must be nonzero |
Builders
Section titled “Builders”The class-based definitions, such as Position2DTween, and your own subclasses of TweenDefinition<TTarget, TValue> are mutable. They inherit TweenOptionsBuilder, the mutable form of TweenOptions, and each start snapshots them. IntelliSense hides the built-in classes and offers the Tweens.* structs instead.
A shorthand method’s configure callback receives one of these builders: TweenPosition on a Node2D passes a Position2DTween. Write reusable configure methods against TweenOptionsBuilder.
By, factors, and deltas work withint,float,double, vector,Color,Quaternion, andRect2values.Byreads the property back on every update. IfReaddoesn’t return whatWritestored, overrideReadsWrittenValueto returnfalse, andByis added to the start value instead.- Don’t change reference-valued configuration while playbacks share it.
tweens.gd is made with math & ferrets, copyright © 2026 its contributors.
Godot logo by Andrea Calabró, licensed under CC BY 4.0.
"Easy, the Ferret" illustrations drawn by foxy_maria.
tweens.gd is released under the MIT License.
Godot is licensed under the MIT License.
tweens.gd is not affiliated with or endorsed by the Godot Foundation.