Runtime Documentation
tip
All the functions below can also be called directly from c++.
Baking
There are 2 functions exposed to blueprints for baking meshes at runtime.
tip
Both baking functions do NOT modify the original mesh that is passed in. They makes a copy before baking, and only modify that copy.
important
IMPORTANT: All baking functions are asynchronous, you must use the callback parameter to know when they are actually complete.
Bake Morphs From Preset
Bakes the morphs on the SkeletalMesh based on the *runtime preset* that is passed in. The bulk matching logic is identical to the [editor version](editor-docs#bulk-matching) in the MorphTools editor.
Definition
Parameter | Type | Description |
---|---|---|
SkeletalMesh | USkeletalMesh* | The mesh to set the morphs on and bake |
Preset | UMorphToolsRuntimePreset* | The runtime preset to use. This can be constructed dynamically at runtime of exported from the MorphTools editor |
bOverrideIndividualSettings | bool | Whether or not to override the individual bake settings |
Callback | Function | Callback function. Returns the baked SkeletalMesh. |
InMorphData | UMorphToolsRuntimeData* | UE5+ Only: The runtime data for the bake, this must be generated in editor and packaged with your game. You can create it by right clicking on the mesh -> Morph Tools Actions -> Generate Runtime Data |
Return Type : void
Bake Morphs
Bakes the morphs on the SkeletalMesh of the passed in SkeletalMeshComponent. The baked mesh will be automatically assigned to the USkeletalMeshComponent after baking is completed. If the BulkMatchSettings array is empty or not supplied, ALL morphs will be baked, but NOT removed. In this version, the morph weights are taken from the weight array on the SkeletalMeshComponent, so the morphs must be set on the mesh component first. If the morphs are set in the same engine loop as you are baking, you will need to set the delay parameter to true to give the values time to propagate.
Definition
Parameter | Type | Description |
---|---|---|
SkeletalMeshComponent | USkeletalMeshComponent* | the SkeletalMeshComponent with the skeletal mesh to bake |
BulkMatchSettings | const TArray<FMorphMatchData> | optional array of bulk match settings |
bDelay | bool | false by default, the delay (of 1s) is only needed to give the morphs time to propagate if the morphs were set during the same engine loop that this function is called |
Callback | Function | Callback function. Returns void. |
InMorphData | UMorphToolsRuntimeData* | UE5+ Only: The runtime data for the bake, this must be generated in editor and packaged with your game. You can create it by right clicking on the mesh -> Morph Tools Actions -> Generate Runtime Data |
Return Type : void
Saving and Loading
!!> IMPORTANT: All saving and loading functions are asynchronous, you must use the callback parameter to know when they they are actually complete!
Save Baked Mesh
Serializes a baked skeletal mesh into a FMorphToolsSerializedMesh for saving. In the example project I show you how to save it in the Save Game.
Definition
Parameter | Type | Description |
---|---|---|
Callback | Function | Callback function. Returns FMorphToolsSerializedMesh |
MeshToSave | USkeletalMesh* | the mesh to save |
OriginalMesh | USkeletalMesh* | a pointer to the original, unbaked mesh |
Data | UMorphToolsRuntimeData* | UE5+ Only: The runtime data for the bake, this must be generated in editor and packaged with your game. You can create it by right clicking on the mesh -> Morph Tools Actions -> Generate Runtime Data |
bSaveMorphTargets | boolean | whether or not to save morph targets to disc |
Return Type : void
Load Baked Mesh
Deserialize a baked mesh that was serialized from "Save Baked Mesh"
Definition
Parameter | Type | Description |
---|---|---|
InBakedMesh | FMorphToolsSerializedMesh. | the mesh to load |
Callback | Function | Callback function. Returns USkeletalMesh* |
Return Type : void
Utility Functions
Apply Preset Morphs To MeshComponent
Applies all morph weights in a Runtime Preset to a Skeletal Mesh Component.
Definition
Parameter | Type | Description |
---|---|---|
SkeletalMeshComponent | USkeletalMeshComponent* | the mesh to apply the preset to |
Preset | UMorphToolsRuntimePreset* | Preset to apply |
Return Type : void
Get Skeletal Mesh Size Bytes
Return the current size, in bytes of the passed in SkeletalMesh.
Definition
Parameter | Type | Description |
---|---|---|
SkeletalMesh | USkeletalMesh* | the mesh to get the size of |
Return Type : int32
Force Garbage Collection
Forces the UE4 garbage collection to do its thing as soon as it can. Included for demonstration only, dont use in production.
Definition
Parameter | Type | Description |
---|---|---|
bFullPurge | bool |
Return Type : void
Object Reference
Note about this section
- Not all classes and structs are shown here, only the ones relevant to the blueprint functions above.
- Only properties are listed.
enum EBakeAction
File: MorphToolsDatatypes.h
UENUM(BlueprintType)
enum class EBakeAction : uint8
{
Bake,
Remove,
Blacklist
};
enum EMatchType
File: MorphToolsDatatypes.h
UENUM(BlueprintType)
enum class EMatchType : uint8
{
Contains,
StartsWith,
EndsWith,
DoesNotContain,
Wildcard
};
struct FMorphMatchData
File: MorphToolsDatatypes.h
/*.
* The data representation of a single row of the "Bulk Rules List"
*/
USTRUCT(BlueprintType)
struct MORPHTOOLSRUNTIME_API FMorphMatchData
{
GENERATED_USTRUCT_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
EMatchType MatchType = EMatchType::Contains;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
EBakeAction BakeAction = EBakeAction::Bake;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FString MatchText;
};
struct FMorphPresetData
File: MorphToolsDatatypes.h
/*
* A representation of single "Morph Setting".
* The data representation of a single row of the "Morphs Panel"
*/
USTRUCT(BlueprintType)
struct MORPHTOOLSRUNTIME_API FMorphPresetData
{
GENERATED_USTRUCT_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FName MorphName;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float MorphWeight;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bBlackList;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bBake;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bRemove;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float RandMin;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float RandMax;
};
struct FMorphToolsMesh
File: MorphToolsDatatypes.h
/*
* this class is basically a wrapper around a USkeletalMesh.
* It holds all "per morph" weights and preset data for a single mesh.
* Picture it as the data representation of a
* single mesh in the "meshes panel" of the Editor
*/
USTRUCT()
struct MORPHTOOLSRUNTIME_API FMorphToolsMesh
{
GENERATED_USTRUCT_BODY()
public:
// holds data pertaining to individual morph settings
// key is the name of the morph for fast lookup
UPROPERTY(EditAnywhere)
TMap<FName, FMorphPresetData> PerMorphData;
UPROPERTY(EditAnywhere)
USkeletalMesh* SkeletalMesh = nullptr;
// Is master Mesh or not
UPROPERTY(VisibleAnywhere)
bool bIsMainMesh = false;
UPROPERTY(EditAnywhere)
FString MeshKey;
};
class UMorphToolsRuntimePreset
File: MorphToolsRuntimePreset.h
UCLASS(Blueprintable, NotPlaceable)
class MORPHTOOLSRUNTIME_API UMorphToolsRuntimePreset : public UDataAsset
{
GENERATED_BODY()
public:
//is TMap for faster lookup
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TMap<FName, FMorphPresetData> MorphPresetData;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<FMorphMatchData> BulkMatchSettings;
};