<!--
{
  "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/encode(to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation14FromToByActionV6encode2toys7Encoder_p_tKF"
  },
  "title" : "encode(to:)"
}
-->

# encode(to:)

Writes the action data into an encoder.

```
func encode(to encoder: any Encoder) throws
```

## Parameters

`encoder`

The encoder to write data to.

## Discussion

If the value fails to encode anything, `encoder` will encode an empty
keyed container. This function throws an
<doc://com.apple.documentation/documentation/Swift/Error> if any values
are invalid for the given encoder’s format.

---

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)