---
title: "encode(to:)"
framework: realitykit
role: symbol
role_heading: Instance Method
path: "realitykit/fromtobyaction/encode(to:)"
---

# encode(to:)

Writes the action data into an encoder.

## Declaration

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

## Parameters

- `encoder`: The encoder to write data to.

## Discussion

Discussion If the value fails to encode anything, encoder will encode an empty keyed container. This function throws an Error if any values are invalid for the given encoder’s format.
