<!--
{
  "availability" : [
    "iOS: 15.0.0 - 18.0.0",
    "iPadOS: 15.0.0 - 18.0.0",
    "macCatalyst: 15.0.0 - 18.0.0",
    "macOS: 12.0.0 - 15.0.0",
    "visionOS: 1.0.0 - 2.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/TextureResource/generate(from:withName:options:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation15TextureResourceC8generate4from8withName7optionsACSo10CGImageRefa_SSSgAC13CreateOptionsVtKFZ"
  },
  "title" : "generate(from:withName:options:)"
}
-->

# generate(from:withName:options:)

Synchronously creates a texture resource from an in-memory Core Graphics image.

```
@MainActor @preconcurrency static func generate(from cgImage: CGImage, withName resourceName: String? = nil, options: TextureResource.CreateOptions) throws -> TextureResource
```

## Parameters

`cgImage`

The source image.

`resourceName`

A unique name for syncing the texture resource across the network.
The name is empty if you don’t include one.

`options`

A configuration for generating the texture.

## Return Value

A texture resource.

## Discussion

This method creates a texture resource from an existing
<doc://com.apple.documentation/documentation/CoreGraphics/CGImage> with
specific options.

RealityKit uses the resource name to identify
resources, and to match texture resources between networked peers.
Specify a unique name for each texture resource you load or generate.

---

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)