# Runtime Function Library

{% hint style="info" %}
Check out the [example project](example-project) for example usage of most of these functions
{% endhint %}

## Bake Morphs From Preset Async

Bakes the morphs on the `SkeletalMesh` based on the preset passed in.

**Parameters:**

* `BakeParameters`: The bake parameters

**Returns:**

* A baked SkeletalMesh Asset

**Note:**

* This version does not require the morphs to be set on the mesh beforehand.
* No delay is needed for this function.
* Does not modify the original mesh; it makes a copy before baking.
* Important: This function is asynchronous, and you must use the callback to know when it is done.

<figure><img src="https://1288554170-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FchK2P12ril2YKyFPCihK%2Fuploads%2FjOw0tMR8a1uH90qWhQAW%2Fimage.png?alt=media&#x26;token=30252235-a11b-4495-97c9-817efad97d41" alt=""><figcaption></figcaption></figure>

## Bake Morphs Async

Bakes the morphs on the `USkeletalMesh` of the provided `USkeletalMeshComponent`.

**Parameters:**

* `BakeParameters`: The bake parameters

**Returns:**

* Nothing

**Note:**

* A copy of the skeletal mesh is made first, ensuring the original mesh remains unaffected.
* The copy is automatically assigned to the `USkeletalMeshComponent` after the baking process is completed.
* If `BulkMatchSettings` is not supplied or empty, all morphs will be baked.
* Morph values to be baked must already be set on the `SkeletalMeshComponent` in this version.
* Retrieve the baked mesh from your mesh component and save it in your save game system.

<figure><img src="https://1288554170-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FchK2P12ril2YKyFPCihK%2Fuploads%2FxOYRL2skAm5StrOJCmBv%2Fimage.png?alt=media&#x26;token=4859e517-6cb0-4b30-9d76-0899dd98efb3" alt=""><figcaption></figcaption></figure>

## Copy Mesh Morphs Async

Copy morphs from any number of source meshes to a target mesh.

<figure><img src="https://1288554170-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FchK2P12ril2YKyFPCihK%2Fuploads%2FRfL6uH1kPzNPIzEZvUmK%2Fimage.png?alt=media&#x26;token=92cf1de0-e07d-4d58-8150-b03c45202ac7" alt=""><figcaption></figcaption></figure>

## Save Baked Mesh

Serializes a baked skeletal mesh into an FMorphToolsSerializedMesh for saving. In the example project I show you how to save it in the Save Game

<figure><img src="https://1288554170-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FchK2P12ril2YKyFPCihK%2Fuploads%2FQWTmJTJZ8yY5mQbHQYSh%2Fimage.png?alt=media&#x26;token=9a2efa03-ca9e-4422-883b-48eec35905fe" alt=""><figcaption></figcaption></figure>

## Load Baked Mesh

Deserialize a baked mesh that was serialized from "Save Baked Mesh"

<figure><img src="https://1288554170-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FchK2P12ril2YKyFPCihK%2Fuploads%2FmCc2l6CsNyErBD5nqVka%2Fimage.png?alt=media&#x26;token=2d3ee2ad-e663-449a-bb98-2afbf2a1b280" alt=""><figcaption></figcaption></figure>

## Remove Vertices From Mesh

Constructs a new mesh using the `Mesh` parameter as a template, permanently removing vertices based on the data in `VertsToRemove`.

**Parameters:**

* `Mesh`: The template mesh.
* `VertsToRemove`: Vertices to be removed.
* `RuntimeData` (optional): Required if you want the new mesh to have its morph targets intact.

**Note:**

* Do not use this function if baking the mesh. Instead, use "Bake Morphs From Preset Async" or "Bake Morphs Async" to avoid building the mesh twice.

**Returns:**

* A new skeletal mesh with removed vertices.

<figure><img src="https://1288554170-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FchK2P12ril2YKyFPCihK%2Fuploads%2FeFpyPiK3eanzLJvrOT7N%2Fimage.png?alt=media&#x26;token=9ea645c3-1c9a-40d9-8e4c-93262a093970" alt=""><figcaption></figcaption></figure>

## Combine Vertex Mask Assets

Combines multiple vertex mask assets into a single mask.

**Parameters:**

* `Assets`: Array of vertex mask assets to combine.

**Returns:**

* A combined vertex mask asset.

<figure><img src="https://1288554170-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FchK2P12ril2YKyFPCihK%2Fuploads%2FHYxSos8vqsCOK2jupqtK%2Fimage.png?alt=media&#x26;token=d87aaf57-c6ea-420e-b87f-d00ea7f34537" alt=""><figcaption></figcaption></figure>

## Derive Vertex Mask From MorphTarget

Derives a vertex mask from morph target names.

**Parameters:**

* `MorphNames`: Array of morph target names.
* `Data`: Morph tools runtime data.

**Returns:**

* A vertex mask derived from the specified morph targets.

<figure><img src="https://1288554170-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FchK2P12ril2YKyFPCihK%2Fuploads%2FDLuboI9cj4Ct3NDavL42%2Fimage.png?alt=media&#x26;token=c8c17e48-dce8-4d00-8461-1cc69b1a702c" alt=""><figcaption></figcaption></figure>

## Combine Mask Textures

Combines multiple opacity mask textures into one.  They must all be the same dimension. Only the red channel is used.

**Parameters:**

* `Masks`: Array of opacity mask textures with identical dimensions.

**Returns:**

* A combined opacity mask texture.

<figure><img src="https://1288554170-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FchK2P12ril2YKyFPCihK%2Fuploads%2FpEvd5d24C442qcQBrca5%2Fimage.png?alt=media&#x26;token=3647349e-fa20-4923-88ed-4e21b7ee6805" alt=""><figcaption></figcaption></figure>

## InitializePresetMapFromComponent

Initializes a new preset map with morph weights from the provided skeletal mesh component.

**Parameters:**

* `Component`: The skeletal mesh component.
* `PresetDataList`: Output map for preset data.

## ApplyPresetMorphsToMeshComponent

Applies morph weights based on the preset to the specified skeletal mesh component.

**Parameters:**

* `SkeletalMeshComponent`: The target skeletal mesh component.
* `Preset`: The morph tools runtime preset.

## GetSkeletalMeshSizeBytes

Returns the estimated size, in bytes, of the specified skeletal mesh.

**Parameters:**

* `SkeletalMesh`: The skeletal mesh.

**Returns:**

* The size of the skeletal mesh in bytes.

## ForceGarbageCollection

Forces the garbage collector to free memory. Use with caution.

**Parameters:**

* `bFullPurge` (optional): If true, performs a full purge.

**Note:**

* Included for demonstration purposes only.

## InitializeMorphCopyOptions

Initializes morph copy options with specified parameters.

**Parameters:**

* `NumSmoothingVerts`: Average number of vertices to take into account.
* `bUseWeightedAverage`: Use weighted average when averaging vertex effects.
* `bOverwrite`: Overwrite existing morphs.
* `PositionTolerance`: Max distance for morph projection.
* `SpecificMorphsList`: Optional newline delimited list of specific morphs to copy.
* `OffsetMagnitude`: Add this to multiply the morph value farther in the direction of the morph target.

**Returns:**

* Morph copy options object.

## Update Per Poly Collision

Updates the per poly collision shape for a SkeletalMeshComponent

**Parameters:**

* `SkeletalMeshComponent`: The target skeletal mesh component.
* `NewPositions`: Array of new positions (Vectors)

<figure><img src="https://1288554170-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FchK2P12ril2YKyFPCihK%2Fuploads%2FzgcwRTYHX0VjDrIpaj5J%2Fimage.png?alt=media&#x26;token=24bd50dc-d36a-4ee0-8fb1-244dedbd2de1" alt=""><figcaption></figcaption></figure>
