<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/FromToByAction",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation14FromToByActionV"
  },
  "title" : "FromToByAction"
}
-->

# FromToByAction

An action that starts, stops, or increments by a specific value.

```
struct FromToByAction<Value> where Value : AnimatableData
```

## Overview

This action animates a bound parameters value over time. Specifying a [`from`](/documentation/RealityKit/FromToByAction/from)
value represents the animated properties’ initial value at the start of the animation. Specifying a [`to`](/documentation/RealityKit/FromToByAction/to)
determines the value of the property at the end of the animation. Specifying a[`by`](/documentation/RealityKit/FromToByAction/by) adds a value to the
properties initial state, which calculates the value at the end of the animation.

This action exposes [`FromToByAction.TransformMode`](/documentation/RealityKit/FromToByAction/TransformMode) which is used when animating a [`Transform`](/documentation/RealityKit/Transform) property.
Use this mode to determine the reference space the property is relative to. For example, [`FromToByAction.TransformMode.local`](/documentation/RealityKit/FromToByAction/TransformMode/local) means
the provided transforms are relative to the transform of the bound entity. The only exception is when [`by`](/documentation/RealityKit/FromToByAction/by) is
specified, this is relative to the space of the starting transform.

> Note: `FromToByAction` doesn’t support ``doc://com.apple.RealityKit/documentation/RealityKit/JointTransforms`` or ``doc://com.apple.RealityKit/documentation/RealityKit/BlendShapeWeights`` types.
> Use ``doc://com.apple.RealityKit/documentation/RealityKit/FromToByAnimation`` to animate these types.

### Creating a from, to, by action to animate an entity’s opacity

The example below creates an animation which gradually animates the bound  entity’s
opacity property for five seconds with a linear transition.
In this example, the entity starts with opacity at `1.0`.

```swift
// Create an action that gradually animates a float value
// towards `0.0`, with a linear transition.
//
// This action does not have a `from` value supplied, 
// meaning this starts from the default source value.
let opacityAction = FromToByAction<Float>(to: 0.0,
                                          timing: .linear,
                                          isAdditive: false)

// A five second animation that plays an animation causing the entity to
// gradually animate the `.opacity` property towards `0.0`.
//
// This makes the entity fade-out.
let opacityAnimation = try AnimationResource
    .makeActionAnimation(for: opacityAction,
                         duration: 5.0,
                         bindTarget: .opacity)

// Play the five second animation on the entity that will fade-out.
entity.playAnimation(opacityAnimation)
```

### Create a from, to, by action to animate an entity’s transform property

The example below creates an animation which gradually animates the bound entities
transform property for five seconds with a linear transition.

```swift
// Create a transform to start animating from.
let startTransform = Transform(translation: [0.0, 2.0, 0.0])

// Create a transform to animate towards.
let endTransform = Transform(translation: [0.0, -2.0, 0.0])

// Create an action that gradually animates a transform value.
//
// This starts `from` a specified value, and animates towards
// a specified `to` value.
//
// The bound entity will move in the space relative to its parent.
let transformAction = FromToByAction<Transform>(from: startTransform,
                                                to: endTransform,
                                                mode: .parent,
                                                timing: .linear,
                                                isAdditive: false)

// A five second animation that plays an animation causing 
// the entity to gradually move from a specific start, and end transform
let transformAnimation = try AnimationResource
    .makeActionAnimation(for: transformAction,
                         duration: 5.0,
                         bindTarget: .transform)

// Play the five second animation on the entity that will cause it to move.
entity.playAnimation(transformAnimation)
```

> Note: The default source value is the base value of the of animated property. If
> multiple animations target the property, then the framework observes the
> output of the previous animation as the subsequent animation’s default
> source value.

> Important: This action animates various bound properties, for example ``doc://com.apple.RealityKit/documentation/RealityKit/BindTarget/transform`` on the bound entity.
> Ensure a correct bind target is supplied when creating the animation.

> Note: For more information on the combination of inputs this action supports see ``doc://com.apple.RealityKit/documentation/RealityKit/FromToByAnimation``.

> Important: If you do not provide values for any of the `from`, `to`, and `by` parameters,
> the animation stays at the default source value.

## Relationships

### Conforms To

[`EntityAction`](/documentation/RealityKit/EntityAction)

[`Encodable`](/documentation/Swift/Encodable)

[`Decodable`](/documentation/Swift/Decodable)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)