Step-by-Step Guide
This guide will help you set up a simple example that uses all the core features: Skeletal Morphing, Morph Target Animation, and Body Part Dismemberment.
You can add EasyMorph to your Unreal Engine Project by using the "Add to Project" button in the Epic Games Launcher . EasyMorph was built to be as non-intrusive as possible. Everything needed to use it is located in the EasyMorph/Core Folder. Check out the EasyMorph/Examples Folder to see how this tool can be used and how you can set up different use cases.
Initial Setup
We will first create all the required Blueprint Classes for this Tutorial/Example.
- Create a Character (we will name it ExampleCharacter henceforth) and add the EasyMorphComponent.
- Open the Character Blueprint, Select the Skeletal Mesh Component, and then choose a SkeletalMesh (in this example, we will use SKM_Manny_Simple, an alteration of the default Manny SkeletalMesh with Morph Targets).
- Create an Animation Blueprint (We name it ABP_ExampleCharacter) that uses the correct Skeleton (SK_Mannequin in our example) and set the Animation Class on the Skeletal Mesh Component to use the newly created Animation Blueprint.
- You might want to move and rotate the Skeletal Mesh in the Blueprint Viewport so it faces the X-Axis and its feet are at the bottom of the capsule collider (In our Example: Location (X=0.000000,Y=0.000000,Z=-90.000000) and Rotation (Pitch=0.000000,Yaw=-90.000000,Roll=0.000000))
Animation Blueprint
The Animation Blueprint will require the most setup if we look at the number of nodes. However, most of it will be copied & pasted with slight changes to the nodes so we can handle all the Bones.
- In the Event Graph, get a Reference to the owning Pawn or Actor. It's best to store this reference in a Variable and use a IsValid Node or Validate Get Node to check whether the Owner exists.
- You can do a similar setup to get a Reference to the EasyMorphComponent attached to the Owner. Use the GetComponentByClass Node and promote its return Value to a Variable. Use an IsValid or Validated Get Node to ensure a valid reference to the Component exists.
- Now we can use the EasyMorphComponent Variable to get whether SkeletalMorphingEnabled is true and also GetAllCurrentSkeletalMorphValues and store the returned values as local Variables on the Animation Blueprint. You should now have a bool Variable we can call IsSkeletalMorphEnabled and a Map of Name & Transform that we can name CurrentSkeletalMorphValues.
- We can now switch to the Anim Graph. Create a Cached Pose from your current Locomotion Output and name it BasePose. We will use this cached pose to switch on and off Skeletal Morphing depending on whether we need it.
- Create a UseCachedPose Node and set it to BasePose. Add a Local To Component Node to start modifying the bones (needed for skeletal morphing).
- Get the CurrentSkeletalMorphValues variable we previously created and add a Find node after it. In the name field you can enter the name of any of the bones you wish to morph. We will use the head in this Tutorial.
- Add a Transform (Modify) Bone Node to the Execution Path (from LocalToComponent Node) and select the Bone to Modify (head in our example). Change the Settings on the node so that the Translation Mode and Rotation Mode are set to Add Existing and Component Space while Scale Mode is set to Replace Existing (Both Component Space and World Space should work here depending on your needs.)
- Connect the Output from the Find Node to the Transform (Modify) Bone and attach a Component To Local Node to the Transform Node.
- Create a new Save Cached Pose and name it Skeletal Morph End.
- We can now connect a Blend Poses by bool Node to the Output Node and connect the Use cached pose "Skeletal Morph End" Node, Use cached pose "Base Pose" Node, and the bool Variable IsSkeletalMorphEnabled to it.
- We have finished a minimal Skeletal Morph setup where we can morph the head. To enable more Bones we simply have to repeat Steps 6-8 for every Bone we wish to support. Check out the Getting Started page for an example Animation Blueprint with most of the Mannequin's Bones set up.
Character Blueprint
In this Blueprint, we must set up our Morphs on the EasyMorphComponent and call some example functions from the Event Graph.
- Select the EasyMorphComponent, locate the SkeletalMorphSetup variable and Add an element to it. Name this Skeletal Morph Setup HeadExample. If the size of our Character does not change due to the Morph or if we want to manually handle any size changes, you can deactivate Auto Adjust Capsule Collider. We will deactivate it for this Tutorial (Check out the Examples to see how it works).
- Add an Element to the BoneList.
- Specify the BoneName (head) and the TargetTransform (Example: Scale -> (X=2.000000,Y=2.000000,Z=2.000000)). You can deactivate Location and Rotation morphs if you don't need it.
- (Optional) Supply a Transition Curve for the Scaling Morph. Otherwise, it will linearly interpolate between the current value and the Target Transform.
- Repeat steps 2-4 for every bone you would like to morph (They also need to be set up in the Animation Blueprint).
- Go to the Event Graph and add the BeginPlay Node.
- From the BeginPlay Node, use the execution path to add a PlaySkeletalMorph node (the EasyMorphComponent Reference should auto-create) and specify the Skeletal Morph that should be played (HeadExample) and the animation duration.
Morph Target Animation
The Character used in this Tutorial has some Morph Targets. We can create animations/transitions using the EasyMorphComponent.
- Locate the Morph Target Animation Setup Variable on the EasyMorphComponent and Add an Element to it.
- Name the newly created setup Wolf and set the MorphTargetName to the Morph Target Name you wish to transition to. In our Tutorial, we use MT_Creature_Wolf.
- Set the Target Value to 1.0 (Should typically be the maximum intended Morph with most Morph Targets)
- (Optional) Provide a TransitionCurve if you do not want a linear interpolation between Start and Target Value
- Go to the Event Graph and from the EasyMorphComponent Get Node create a PlayMorphTargetAnimation Node. Make sure it is connected to the Execution Path.
- Set the MorphTargetAnimation to the previously created Wolf and change the duration as you see fit.
Dismemberment
We can use the existing setup for Skeletal Morphing to enable the dismemberment of Body Parts.
To achieve the best results, Body Parts should be Skeletal Meshes that retain the same Bone Hierarchy and have the same Morph Targets as the Full Body Skeletal Mesh.
- Locate the BodyPartsSetup Variable on the EasyMorphComponent and Add an Element to it.
- Name it head (it Must be the name of a Bone) and specify which Mesh and/or Particle System should be used when this Body Part gets cut off. In this Tutorial, we will use SKM_Manny_Head.
- Create a new Animation Instance to be used when the dismembered head gets instantiated, and name it ABP_HeadExample. The Animation Instance should use the SKM_Manny_Head_Skeleton.
- Open the Animation Blueprint and goto Class Settings and add the BPI_EasyMorphBodyPartAnim Interface.
- Implement both Interface Events that should have popped up in the My Blueprint Tab (Might need to Compile).
- Create a bool Variable and name it IsSkeletalMorphing. The ActivateSkeletalMorphing Event sets the newly created IsSkeletalMorphing bool Variable to true.
- Create a new Variable and set it to Type Name, name it CurrentSkeletalMorphValues, and then change it from a single Variable to Map with the secondary Type being Transform. The SetMorphTransfrom Event adds an Element to the CurrentSkeletalMorphValues Map.
- Copy the setup from the ABP_ExampleCharacter Anim Graph to the ABP_HeadExample Anim Graph. Ensure the Anim Graph uses the Variables we created in the steps above. The ABP_HeadExample only needs the Transform (Modify) Bone nodes that modify Bones that are part of this Body Part.
- Go to the ExampleCharacter Blueprint and on the EasyMorphComponent set the Animation Instance to ABP_HeadExample.
- Go to the Event Graph and add a 5-second Delay node and a DismemberBodyPart Node after the PlayMorphTargetAnimation Node. Specify the Body Part/Bone you want to dismember (head).