<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/ShaderGraph/encode()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:11ShaderGraphAAC6encode10Foundation4DataVyKF"
  },
  "title" : "encode()"
}
-->

# encode()

Encodes the graph into a binary representation.

```
final func encode() throws -> Data
```

## Discussion

The resulting data can be stored to disk or passed across a process boundary,
and later restored with [`init(from:)`](/documentation/RealityKit/ShaderGraph/init(from:)).

> Throws: If the graph cannot be serialized.

---

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)