GDScriptBeta
Definitions
A TweensGdDefinition is a mutable description of one motion. Each start snapshots it, so a change reaches only later starts; with_*() methods return a changed copy instead. Reusable definitions shows the pattern. Keyframes define several parallel value curves in one reusable object.
var arrive := Tweens.position_2d([400, 180], 0.6, Out.CUBIC) # Factoryvar slow := arrive.with_duration(1.2) # Copyarrive.delay = 0.1 # ChangeFactories
Section titled “Factories”Each factory returns a new TweensGdDefinition.
| Factory | Purpose |
|---|---|
Tweens.position_2d(to, seconds, easing, delay) |
Tween a known property, checking the target’s class and the value’s type; every named helper takes these |
Tweens.property(path, to, seconds, easing, delay) |
Tween any property, or a component path such as ^"position:x" |
Tweens.value(from, to, seconds, easing, delay) |
Deliver values to on_update without writing a property |
Tweens.shader_parameter(parameter, to, seconds, easing, delay) |
Tween a ShaderMaterial uniform |
Tweens.instance_shader_parameter(parameter, to, seconds, easing, delay) |
Tween an instance uniform on a CanvasItem or GeometryInstance3D |
Tweens.custom(getter, setter, interpolator, validator) |
Read and write your own storage through Callables; see adapters |
to defaults to null, which uses the property’s value at start. seconds and delay default to 0.0, and easing to linear; it takes In and Out flags or a legacy Tweens.Ease constant. Tweens.custom() needs only its getter and setter.
Helper or property path?
Section titled “Helper or property path?”Both create the same type of definition.
| Named helper | Property path | |
|---|---|---|
| Call | Tweens.position_2d(to, 0.5) |
Tweens.property(^"position", to, 0.5) |
| Checked at start | The target’s class and the value’s type | That the target has the property |
| Reaches | The properties in the helper catalog | Any property on the target, and components such as position:x or region_rect:size:x |
Paths select a property and its value components on the target itself. They can’t traverse nodes or cross into another object; pass that object as the target instead.
Fields
Section titled “Fields”Every definition has the same fields, listed by role:
- Endpoints & variations:
from_value,to_value,by_value, and their factors and deltas. - Timing:
duration,delay,offset,repeats,ping_pong, intervals, andfill. - Easing:
ease,blend_type,blend,skew,weks,ease_function, andcurve. - Color interpolation:
color_space,alpha_mode, andcolor_encoding; defaults are OKLab, premultiplied alpha, and sRGB input/output. - Callbacks:
on_addthroughon_finally, andsuppress_callbacks_when_target_invalid.
color_space
Section titled “color_space”Whole-color interpolation defaults to Tweens.ColorSpace.OKLAB; SRGB and LINEAR_RGB select other working spaces.
alpha_mode
Section titled “alpha_mode”Tweens.AlphaMode.PREMULTIPLIED is the default. STRAIGHT interpolates color coordinates and alpha independently.
color_encoding
Section titled “color_encoding”Tweens.ColorEncoding.SRGB accepts ordinary Godot Colors. LINEAR_RGB supports APIs expecting linear values. Input and output use straight alpha. See the color policy for exact endpoints and relative arithmetic.
Binding fields
Section titled “Binding fields”The binding fields choose what a definition animates. Factories set them, and they have no with_*() methods:
| Field | Type | Default | Meaning |
|---|---|---|---|
property |
NodePath |
^"" |
Property path, set by Tweens.property() and the named helpers |
adapter |
TweensGdAdapter |
null |
Adapter for other storage; use it or property, not both |
target_class |
StringName |
&"" |
Target class that a named helper checks at start |
value_type |
int |
TYPE_NIL |
Value type that a named helper checks at start |
Share timing and easing
Section titled “Share timing and easing”GDScript definitions have no separate options object. To give several definitions the same timing and easing, write a function that sets those fields and returns the definition:
static func snappy(definition: TweensGdDefinition) -> TweensGdDefinition: definition.duration = 0.25 definition.ease = Out.CUBIC return definitionChange a setting after the shared function has run, as in snappy(Tweens.scale_2d()).with_duration(0.6).
Methods
Section titled “Methods”| Method | Returns | Meaning |
|---|---|---|
with_duration(seconds) and the other with_*() methods |
TweensGdDefinition |
A copy with one field changed |
copy() |
TweensGdDefinition |
An unchanged copy |
validate() |
String |
Empty when the configuration is valid, or a description of the first problem |
- There’s one
with_*()method for every endpoint, variation, timing, easing, and callback field. They chain, as inpop.with_delay(0.1).with_duration(0.4). - Endpoint methods drop
_value:with_from(),with_to(), andwith_by().with_initial_value()keeps its name. with_ping_pong()andwith_suppress_callbacks_when_target_invalid()default totrue.
Copy on start
Section titled “Copy on start”- Starting snapshots the configuration. Later changes to the definition never reach running playback.
- Preparation and property capture happen on the first eligible update, before any positive delay.
- Callables and the objects they capture stay shared;
curveresources are duplicated for each start. - Each
copy()andwith_*()call creates a new definition object.
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.