---
title: "generate(from:withName:options:)"
framework: realitykit
role: symbol
role_heading: Type Method
path: "realitykit/textureresource/generate(from:withname:options:)"
---

# generate(from:withName:options:)

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

## Declaration

```swift
@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

Return Value A texture resource.

## Discussion

Discussion This method creates a texture resource from an existing 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.

## See Also

### Deprecated

- [generateAsync(from:withName:options:)](realitykit/textureresource/generateasync(from:withname:options:).md)
- [replaceAsync(withImage:options:)](realitykit/textureresource/replaceasync(withimage:options:).md)
- [generate(from:named:options:)](realitykit/textureresource/generate(from:named:options:).md)
- [loadAsync(contentsOf:withName:options:)](realitykit/textureresource/loadasync(contentsof:withname:options:).md)
