# GenerateMeshAsync

> Requests the generation of the Mesh with MeshId meshId. Unity calls onMeshGenerationComplete when generation finishes.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine.XR](/engine/6000.0/script-reference/unityengine/xr.md)
* **Assembly:** UnityEngine.XRModule

## GenerateMeshAsync(MeshId, Mesh, MeshCollider, MeshVertexAttributes, Action\<MeshGenerationResult>)

Requests the generation of the Mesh with [MeshId](/engine/6000.0/script-reference/unityengine/xr/meshid.md) meshId. Unity calls onMeshGenerationComplete when generation finishes.

```csharp
public void GenerateMeshAsync(MeshId meshId, Mesh mesh, MeshCollider meshCollider, MeshVertexAttributes attributes, Action<MeshGenerationResult> onMeshGenerationComplete)
```

### Parameters

**** (\[MeshId]\(/engine/6000.0/script-reference/unityengine/xr/meshid)): The [MeshId](/engine/6000.0/script-reference/unityengine/xr/meshid.md) of the mesh you wish to generate.**** (\[Mesh]\(/engine/6000.0/script-reference/unityengine/mesh)): The [Mesh](/engine/6000.0/script-reference/unityengine/mesh.md) to write the results into.**** (\[MeshCollider]\(/engine/6000.0/script-reference/unityengine/meshcollider)): (Optional) The [MeshCollider](/engine/6000.0/script-reference/unityengine/meshcollider.md) to populate with physics data. This may be null.**** (\[MeshVertexAttributes]\(/engine/6000.0/script-reference/unityengine/xr/meshvertexattributes)): The vertex attributes you'd like to use.**** (\[Action\<MeshGenerationResult>]\(https\://learn.microsoft.com/dotnet/api/system.action)): The delegate to invoke when the generation completes.

### Remarks

Use this method to request that a mesh is asynchronously generated. "Generation" includes extracting the mesh data from the subsystem's mesh provider (e.g., an AR device) and baking the [MeshCollider](/engine/6000.0/script-reference/unityengine/meshcollider.md) (if meshCollider is not null).

This happens in a background thread. For large meshes, this can take several frames to complete. onMeshGenerationComplete is invoked when the generation completes.

The mesh vertices are provided in session space.

Additional Resources: [XRMeshSubsystem.TryGetMeshInfos](/engine/6000.0/script-reference/unityengine/xr/xrmeshsubsystem/trygetmeshinfos.md)

## GenerateMeshAsync(MeshId, Mesh, MeshCollider, MeshVertexAttributes, Action\<MeshGenerationResult>, MeshGenerationOptions)

Requests the generation of the Mesh with [MeshId](/engine/6000.0/script-reference/unityengine/xr/meshid.md) meshId. Unity calls onMeshGenerationComplete when generation finishes.

```csharp
public void GenerateMeshAsync(MeshId meshId, Mesh mesh, MeshCollider meshCollider, MeshVertexAttributes attributes, Action<MeshGenerationResult> onMeshGenerationComplete, MeshGenerationOptions options)
```

### Parameters

**** (\[MeshId]\(/engine/6000.0/script-reference/unityengine/xr/meshid)): The [MeshId](/engine/6000.0/script-reference/unityengine/xr/meshid.md) of the mesh you wish to generate.**** (\[Mesh]\(/engine/6000.0/script-reference/unityengine/mesh)): The [Mesh](/engine/6000.0/script-reference/unityengine/mesh.md) to write the results into.**** (\[MeshCollider]\(/engine/6000.0/script-reference/unityengine/meshcollider)): (Optional) The [MeshCollider](/engine/6000.0/script-reference/unityengine/meshcollider.md) to populate with physics data. This may be null.**** (\[MeshVertexAttributes]\(/engine/6000.0/script-reference/unityengine/xr/meshvertexattributes)): The vertex attributes you'd like to use.**** (\[Action\<MeshGenerationResult>]\(https\://learn.microsoft.com/dotnet/api/system.action)): The delegate to invoke when the generation completes.**** (\[MeshGenerationOptions]\(/engine/6000.0/script-reference/unityengine/xr/meshgenerationoptions)): The mesh generation options.

### Remarks

This variant allows you to specify additional mesh generation options.

**Note:** If the [MeshGenerationOptions.ConsumeTransform](/engine/6000.0/script-reference/unityengine/xr/meshgenerationoptions/consumetransform.md) flag is set in the options argument, the resulting mesh will be relative to the transform provided by the [MeshGenerationResult](/engine/6000.0/script-reference/unityengine/xr/meshgenerationresult.md). If this flag is not set, the vertices are transformed into session space and the [MeshGenerationResult](/engine/6000.0/script-reference/unityengine/xr/meshgenerationresult.md) will contain an identity transform.

Additional Resources: [XRMeshSubsystem.TryGetMeshInfos](/engine/6000.0/script-reference/unityengine/xr/xrmeshsubsystem/trygetmeshinfos.md)
