Navigation
API > API/Plugins > API/Plugins/SkeletalMeshModifiers
API used to modify skin weights on a Skeletal Mesh asset.
To use:
Instantiate an instance of USkinWeightModifier
Call "SetSkeletalMesh(MyMeshAsset)", passing in the skeletal mesh you want to edit weights on
Use Get/Set weights functions, and Normalize/Prune to edit the weights as desired
When ready to commit to the asset, call CommitWeightsToSkeletalMesh() and save the asset if desired
This API can be used from C++, Blueprint or Python. Here is a sample usage of the API in Python:
import unrealcreate a weight modifier for a given skeletal mesh
skel_mesh = unreal.EditorAssetLibrary().load_asset("/Game/Characters/Wolf/Meshes/SK_Wolf") weight_modifier = unreal.SkinWeightModifier() weight_modifier.set_skeletal_mesh(skel_mesh)get weight of vertex 1234
vertex_weights = weight_modifier.get_vertex_weights(1234) print(vertex_weights)remove neck2 as an influence on this vertex
vertex_weights.pop("neck2") weight_modifier.set_vertex_weights(vertex_weights, True) print(vertex_weights)commit change to the skeletal mesh
weight_modifier.commit_weights_to_skeletal_mesh()
OUTPUT: {"head": 0.6, "neck1": 0.3, "neck2": 0.1} {"head": 0.6, "neck1": 0.3}
In Python, the per-vertex weights are stored as a dictionary mapping Bone Names to float weight values.
The "SetVertexWeights()" function expects the same data structure. You can add/remove/edit influences as needed. The SetVertexWeights() function does not normalize the weights. So you can make multiple modifications and call NormalizeVertexWeights() or NormalizeAllWeights() as desired.
The PruneVertexWeights() and EnforceMaxInfluences() functions can be used to trim small influences and clamp the total number of influences per vertex as needed.
Note that it is not required to normalize the weights by calling any of the normalize functions. Or manually before calling SetVertexWeights(). Committing the weights to the skeletal mesh will always enforce normalization.
Though it may be useful to normalize while editing.
| Name | USkinWeightModifier |
| Type | class |
| Header File | /Engine/Plugins/Runtime/MeshModelingToolset/Source/SkeletalMeshModifiers/Public/SkinWeightModifier.h |
| Include Path | #include "SkinWeightModifier.h" |
Syntax
UCLASS (MinimalAPI, BlueprintType)
class USkinWeightModifier : public UObject
Inheritance Hierarchy
- UObjectBase → UObjectBaseUtility → UObject → USkinWeightModifier
Constants
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| LODIndex | int32 | SkinWeightModifier.h |
Variables
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| Mesh | TObjectPtr< USkeletalMesh > | The skeletal mesh that was loaded by SetSkeletalMesh | SkinWeightModifier.h | |
| MeshDescription | TUniquePtr< FMeshDescription > | SkinWeightModifier.h | ||
| Weights | TArray< TMap< FName, float > > | Weights stored in-memory for editing before being committed to the skeletal mesh | SkinWeightModifier.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
bool CommitWeightsToSkeletalMesh () |
Actually applies the weight modifications to the skeletal mesh. | SkinWeightModifier.h |
|
bool EnforceMaxInfluences
(
const int32 MaxInfluences |
Strips out smallest influences to ensure each vertex does not have weight on more influences than MaxInfluences. | SkinWeightModifier.h |
|
| Get an array of all bone names in the skeletal mesh. | SkinWeightModifier.h |
|
|
int32 GetNumVertices() |
Get the total number of vertices in the skeletal mesh. | SkinWeightModifier.h |
|
USkeletalMesh * GetSkeletalMesh() |
Get a reference to the skeletal mesh that was loaded | SkinWeightModifier.h |
|
| Get all bone weights for a single vertex. | SkinWeightModifier.h |
|
|
bool NormalizeAllWeights() |
Normalize weights on all vertices in the mesh. | SkinWeightModifier.h |
|
bool NormalizeVertexWeights
(
const int32 VertexID |
Normalize weights on the specified vertex. | SkinWeightModifier.h |
|
bool PruneAllWeights
(
const float WeightThreshold |
Remove all weights below the given threshold value, on all vertices. | SkinWeightModifier.h |
|
bool PruneVertexWeights
(
const int32 VertexID, |
Remove all weights below the given threshold value, on the given vertex. | SkinWeightModifier.h |
|
bool SetSkeletalMesh
(
USkeletalMesh* InMesh |
Call this first to load the weights for a skeletal mesh for fast editing. | SkinWeightModifier.h |
|
bool SetVertexWeights
(
const int32 VertexID, |
Set bone weights for a single vertex. | SkinWeightModifier.h |
|