Skip to main content

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

ParameterTypeDescription
SkeletalMeshUSkeletalMesh*The mesh to set the morphs on and bake
PresetUMorphToolsRuntimePreset*The runtime preset to use. This can be constructed dynamically at runtime of exported from the MorphTools editor
bOverrideIndividualSettingsboolWhether or not to override the individual bake settings
CallbackFunctionCallback function. Returns the baked SkeletalMesh.
InMorphDataUMorphToolsRuntimeData*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

ParameterTypeDescription
SkeletalMeshComponentUSkeletalMeshComponent*the SkeletalMeshComponent with the skeletal mesh to bake
BulkMatchSettingsconst TArray<FMorphMatchData>optional array of bulk match settings
bDelayboolfalse 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
CallbackFunctionCallback function. Returns void.
InMorphDataUMorphToolsRuntimeData*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

ParameterTypeDescription
CallbackFunctionCallback function. Returns FMorphToolsSerializedMesh
MeshToSaveUSkeletalMesh*the mesh to save
OriginalMeshUSkeletalMesh*a pointer to the original, unbaked mesh
DataUMorphToolsRuntimeData*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
bSaveMorphTargetsbooleanwhether 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

ParameterTypeDescription
InBakedMeshFMorphToolsSerializedMesh.the mesh to load
CallbackFunctionCallback 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

ParameterTypeDescription
SkeletalMeshComponentUSkeletalMeshComponent*the mesh to apply the preset to
PresetUMorphToolsRuntimePreset*Preset to apply

Return Type : void

Get Skeletal Mesh Size Bytes


Return the current size, in bytes of the passed in SkeletalMesh.

Definition

ParameterTypeDescription
SkeletalMeshUSkeletalMesh*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

ParameterTypeDescription
bFullPurgebool

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;
    
};