[Tutorial] 2. Add hand animations
Updated: May 18
In the previous tutorial we created our VR character pawn. In this article we will add hand animations, so we can open and close our fist on a button press.
1. Grip state enumeration
Open the VRPawn blueprint, and add two variables of type GripEnum. Call them LeftGripState and RightGripState. These variables will hold the current state of the hands.
2. Input action (Button press)
Now right-click in the graph editor and find the GrabLeft and GrabRight input actions.
If you can't see these actions, then you need to create them in your Project Settings/Input and map them to the buttons you want to grip with. But, if you created your new project based on the default VR template, then GrabLeft and GrabRight are already there.
Now let's set the value of of the previously created enums. If we press the grip button, we want to close our hand and open it, when we release the button.
3. Animation blueprints
Now, we will have to feed the state of this enum to an Animation blueprint, which will handle the animation of the hands. In the content browser, navigate to Content/Virtual Reality/Mannequin/Animations folder. Here, you can see the animation blueprint called RightHand_AnimBP. Right-click and duplicate it. For simplicity we create a separate anim blueprint for the left and right hands. Call this duplicated blueprint LeftHand_AnimBP. Open both blueprints. Delete the Blueprint Begin Play and the associated nodes. We will only need the Blueprint Update Animation event. In each of this this blueprints there is an internal GripState variable, we need to set this variable to match our GripState variable in our VRPawn.
4. Setting the GripState
Lets's start with the LeftHand_AnimBP. Drag out the GripState variable from the variables panel, drop it into the graph editor and choose 'set'.
From the Try Get Pawn Owner node cast the return value to our VRPawn. Then get LeftHandGripState from the VRPawn and connect it to this this internal GripState variable. This will check our GripState and update it's own state on the tick. The result should look like this:
Now we have repeat the whole process from Step 4, but for the RightHand_AnimBP. The only difference will be, when we get the GripState from the casted VRPawn. We need to get RightGripState instead of the left, and feed that to the internal variable.
The last thing to do is to setup our controllers to use these animation blueprints. Open our VRPawn blueprint, and select the Skeletal Mesh component in the component window. On the right hand side of the window, where we have selected the hand models in the previous tutorial, set the corresponding animation blueprint for the HandMesh - Left and HandMesh - Right components:
Now hit play: