# GDScript: Await Completion

Source: https://tweens.gd/gdscript/playback/

Every start returns a handle. Await it to continue once the tween ends, or use it to pause and cancel the tween on the way.

Interactive preview: https://tweens.gd/gdscript/playback/

## Scripting it

The remote’s buttons call this script’s functions. To build your own, attach it to a scene’s root `Node2D`, pick a `Sprite2D` for **Sprite** in the Inspector, and connect each button’s `pressed` signal to its function.

playback\_remote.gd

```gdscript
extends Node2D
## The remote's buttons call these functions; ended reports how the movement ended.

signal ended(reason: int)

@export var sprite: Sprite2D
@export var to := Vector2(1024, 128)

var movement: TweensGdHandle

func start() -> void:
  movement = Tweens.play(sprite, Tweens.position_2d(to, 2.4, InOut.SMOOTHER_STEP))
  ended.emit(await movement.end)

func pause() -> void:
  movement.pause()

func resume() -> void:
  movement.resume()

func cancel() -> void:
  movement.cancel()
```

1.  **Keep the handle.** `Tweens.play()` returns it at once, and `start()` keeps it in `movement`.
2.  **Await the end.** `await movement.end` resumes once playback ends, with the reason: `COMPLETED`, `CANCELLED`, or `OWNER_EXITED` when the scene closes first.
3.  **Control it.** `pause()` holds the current value until `resume()`. `cancel()` stops for good and keeps the latest value.

To stop every tween a node owns without keeping their handles, call `Tweens.cancel_tweens(sprite)`.

## React to the end

Await the handle to continue in the same function. `end` resumes however playback ended, so check the reason when the next step needs an arrival.

Await

```gdscript
var arrive := Tweens.position_2d([400, 180], 0.6, Out.CUBIC)

var movement := Tweens.play(sprite, arrive)
if await movement.end == Tweens.Reason.COMPLETED:
  print("Arrived")
```

A callback on the definition suits a small synchronous reaction. `on_end` runs only on natural completion.

Callback

```gdscript
var arrive := Tweens.position_2d([400, 180], 0.6, Out.CUBIC) \
  .with_on_end(func(_handle): print("Arrived"))

Tweens.play(sprite, arrive)
```

`on_finally` also runs when playback stops early or fails; [callback order](https://tweens.gd/gdscript/api/callbacks/#callback-order) shows the whole lifecycle.

Await the property itself

Write `await movement.end`, which also works after the end. A cached `ended` signal doesn’t replay, so a later wait on it never resumes. A detected failure ends with `Tweens.Reason.FAILED`, and `movement.error` holds the message.

### Would you like to know more?

[Cancellation](https://tweens.gd/gdscript/cancellation/)Stop tweens early and guard a sequence.

[Sequences](https://tweens.gd/gdscript/sequences/)Link motions or play them together.

[Easings](https://tweens.gd/easings/)Compare easing curves.

[Catalog](https://tweens.gd/gdscript/nodes/)Choose what to animate next.
