GDScriptBeta
Adapters
An adapter animates storage that a property path can’t reach. Pass Callables to Tweens.custom(), or extend TweensGdAdapter for setup and cleanup around each playback and assign an instance to a definition’s adapter. Custom properties walks through both.
# Tweens a camera's zoom as one number, keeping X and Y equal.var zoom := Tweens.custom( func(target): return target.zoom.x, func(target, value): target.zoom = Vector2(value, value))zoom.to_value = 2.0zoom.duration = 0.5
Tweens.play(camera, zoom)# Tweens a camera's zoom as one number, keeping X and Y equal.class_name UniformZoomAdapterextends "res://addons/tweens_gd/adapter.gd"
func read(target: Object) -> Variant: return target.zoom.x
func write(target: Object, value: Variant) -> String: target.zoom = Vector2(value, value) return ""var zoom := TweensGdDefinition.new()zoom.adapter = UniformZoomAdapter.new()zoom.to_value = 2.0zoom.duration = 0.5
Tweens.play(camera, zoom)Callables
Section titled “Callables”| Factory | Purpose |
|---|---|
Tweens.custom(getter, setter, interpolator, validator) |
Read with getter(target) and write with setter(target, value); the optional interpolator(from, to, weight) and validator(value) replace the defaults |
Set endpoints and timing on the returned definition. The Callables and the objects they capture stay shared between starts.
Methods to override
Section titled “Methods to override”Override read and write; the rest are optional. Hooks that return a String return an empty one on success, and an error message to fail playback with FAILED.
| Method | Returns | Purpose |
|---|---|---|
read(target) |
Variant |
Read the current value |
write(target, value) |
String |
Write a value |
interpolate(from, to, weight) |
Variant |
Blend two values; weight leaves 0 to 1 when an ease overshoots. Handles every built-in value type unless overridden |
interpolate_offset(from, to, weight) |
Variant |
Blend relative offsets and factors through interpolate. The base color implementation uses RGBA components. Override this hook only when relative math differs from your custom interpolate |
validate_value(value) |
String |
Reject unsupported or non-finite values. Handles every built-in value type unless overridden |
prepare(target) |
String |
Set up this playback’s state |
restore(target, initial) |
String |
Undo the tween at a non-retaining end; calls write() unless overridden |
release() |
String |
Free this playback’s state |
copy() |
TweensGdAdapter |
Create the per-playback copy; copies script variables shallowly unless overridden |
Binding lifecycle
Section titled “Binding lifecycle”copy(). Each start works on its own copy of the adapter. The default copies script variables shallowly, so Arrays, resources, and captured objects stay shared; overridecopy()when configuration needs another policy.prepare()runs on that copy before the first read. Initialize private playback state here.read()captures the start value.interpolate()andwrite()run on every update.restore()runs at a natural end whose fill doesn’t keep the final value. It can writeinitialback, or remove an override instead.release()runs after the ending callbacks and before waiters resume, and also after a failedprepare(). Release only what this copy owns.
- Adapter constructors must take no arguments.
- An adapter script’s
extendsline needs a path or a global class: the base script’s path, orTweensGdAdapteronce the editor has built its class cache. - If a setter or interpolator cancels its own tween,
release()waits until that call returns. - Several detected failures are kept together in the handle’s
error.
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.