This is what you'll see at the end of this section.
Goals
The purpose of this section is to show you how to add animations for your First Person Shooter character.
Objectives
By the end of this section of the tutorial you'll be able to:
Animate Your Character
Set Up Your Event Graph
Add an Animation State Machine
Add Transition States to Your Animation
Associate the Animation Blueprint with the Character Blueprint
Steps
4.1 - Animating Your Character
4.2 - Setting Up Your Event Graph
4.3 - Adding an Animation State Machine
4.4 - Adding Animation Transition States
4.4.1 - Add Idle to/from Run Transitions
4.4.2 - Add Idle to Jump Start Transition
4.4.3 - Add Run to Jump Start Transition
4.4.4 - Add Jump Start to Jump Loop Transition
4.4.5 - Add Jump Loop to Jump End Transition
4.4.6 - Add Jump End to Idle Transition
4.5 - Associating Animation and Character Blueprints
4.1 - Animating your Character
During this step, you are going to add some animations into your game.
Importing Animations
Before getting started, download and extract the sample animations from the following link:
Right-click in the Content Browser and select New Folder.
Name this new folder Animations and double-click on the created folder to open it.
Locate the five local animation files, namely:
FPP_Idle.FBXFPP_JumpEnd.FBXFPP_JumpLoop.FBXFPP_JumpStart.FBXFPP_Run.FBX
Right-click in the "Animations" folder and click Import to /Game/Animations/... to begin importing the animations.
The FBX Import Options dialog window appears, select HeroFPP_Skeleton under the Select Skeleton heading, then click Import All to import all of the animations.
Make sure that you select the correct destination Mesh before importing your animations! Failing to do so can cause some issues when you go to map animations later.
You should now have all five animations inside of the Animations folder in the Content Browser.
Click the File in the Main menu panel, select Save All to save your imported mesh.
Creating the Animation Blueprint
Navigate to the Animation folder of the Content Browser, right-click in the file window, select the Animation > Animation Blueprint.
Select AnimInstance as the Parent Class and choose HeroFPP_Skeleton as the Target Skeleton.
Name the created animation Blueprint Arms_AnimBP.
Double-click Arms_AnimBP to open it in the Blueprint Editor.
Adding State Machine Transition Variables
In the My Blueprint panel, click on the Add* button and select Variable**.
Make the variable a Boolean (by defaults, but check the Details panel to be sure) and name it IsRunning.
In the My Blueprint panel, click on the Add button and select Variable.
Make the variable a Boolean and name it IsFalling.
You should now have two animation transition variables that will drive the state machine of the animation.
Keep Arms_AnimBP open when moving on to the next section.
4.2 - Setting up your Event Graph
During this step, you are going to edit the Event Graph of the animation to ensure that your animation transition variables are firing properly while the game is running.
Updating your State Variables
Open Arms_AnimBP if you have not already done so.
Open the event graph by double-clicking on EventGraph in the My Blueprint panel.
Right-click in the Graph to bring up the Context Menu, search for and select the Event Blueprint Update Animation node.
The Event Blueprint Update Animation node allows you to update your state variables every time the Animation updates so that they are always in sync with the game state.
Blueprintcontext_graphRight-click in the Graph to bring up the Context Menu, search for and select the Try Get Pawn Owner node.
Blueprintcontext_graphRight-click in the Graph to bring up the Context Menu, search for and select the Cast to Character node.
Blueprintcontext_graphConnect pins of added nodes as following.
Blueprintcontext_graphDrag off the As Character output pin of the Cast to Character node, search for and select Get Character Movement node (disable Context Sensitivity to locate this node).
Blueprintcontext_graphDrag off the Character Movement output pin, search for and select Get Movement Mode node (disable Context Sensitivity to locate this node).
Blueprintcontext_graph
Querying Character Movement
Drag off the Movement Mode output pin, search for and select Equal (Enum) node (disable Context Sensitivity to locate this node).
Determining if the Character is Falling
Set the dropdown value on the Equal (Enum) node to Falling.
Navigate to the My Blueprint panel, press Alt and drag off IsFalling variable to the Graph to create the Set Is Falling node.
Blueprintcontext_graphConnect the output execution pin of the Cast to Character node to the input execution pin of the Set Is Falling node, connect the output pin of the Equal (Enum) node to the input Is Falling pin of the Set Is Falling node. Your Blueprint Script should look like the following:
Blueprintcontext_graphClick image for the full view
Determining if the Character is Running
Go back to the Cast To Character node and drag off the As Character pin again. This time, search for and select the Get Velocity node.
Blueprintcontext_graphIf the character is not standing still, the length of its velocity vector will be greater than zero. So, drag off the Return Value output pin of the Get Velocity node and select Vector Length node.
Blueprintcontext_graphDrag off the Return Value float output pin of the Vector Length node, search for and select the Greater node.
Blueprintcontext_graphNavigate to the My Blueprint panel, press Alt and drag off IsRunning variable to the Graph to create the Set Is Running node.
Blueprintcontext_graphConnect the output execution pin of the Set Is Falling node to the input execution pin of the Set Is Running node. Connect the output pin of the Greater node to the Is Running pin of the Set Is Running node.
Your Event Graph should now look like the following:
Blueprintcontext_graphClick Compile and Save buttons.
4.3 - Adding an Animation State Machine
During this step, you are going to put together a state machine that will take advantage of your newly-made variables.
Navigate to the My Blueprint panel, double-click on AnimGraph to open it.
Right-click the Graph and select State Machines > Add New State Machine... in the Context Menu.
Right-click on the New State Machine in the My Blueprint panel and name it "Arms State Machine".
Connect the output execution pin of the Arms State Machine node to the Result input execution pin of the Final Animation Pose node.
Double-click the Arms State Machine node to open its graph for editing.
4.4 - Adding Animation Transition States
During this step, you're going to add five states to the state graph, namely:
Idle
Run
JumpStart
JumpEnd
JumpLoop
Right-click in the graph and select Add State... from the context menu.
Name the state Idle.
Double-click the state to begin editing it.
Right-click in the Graph area, search for and select Play FPP_Idle node.
Connect the output execution pin of the Play FPP_Idle node to the Result input execution pin of the Output Animation Pose node.
Repeat steps 1-6 for each of the other 4 states, namely: Run (Play FPP_Run > Output Animation Pose) JumpStart (Play FPP_JumpStart > Output Animation Pose) JumpEnd (Play FPP_JumpEnd > Output Animation Pose) JumpLoop (Play FPP_JumpLoop > Output Animation Pose)
When you are done, the Arms State Machine graph should look like the following image:
Each state should contain its Play node connected to a respective Final Animation Pose node.
Drag a wire from the Entry node to the Idle state node.
4.4.1 - Add Idle to/from Run Transitions
During this step, you are going to set the Idle to and from run transitions so that when your character starts moving, the state machine will transition from Idle to Run.
Drag a wire from the Idle state to the Run state to create a transition.
Double-click the transition to edit it.
Navigate to the My Blueprint panel, press Ctrl and drag off IsRunning variable to the Graph to create the Get Is Running node.
Connect the output pin from the Get Is Running node to the Can Enter Transition input pin of the Result node.
Blueprintcontext_graphWhen your character stops moving, the state machine should transition from the Run state to the Idle state.
Return to the Arms State Machine graph and drag a wire from the Run state to the Idle state.
Double-click the transition to edit it.
Navigate to the My Blueprint panel, press Ctrl and drag off IsRunning variable to the Graph to create the Get Is Running node.
Drag off the output pin of the Get Is Running node, search for and select Not Boolean node.
Connect the output pin from the Not Boolean node to the Can Enter Transition input pin of the Result node.
Blueprintcontext_graph
4.4.2 - Add Idle to Jump Start Transition
During this step, you are going to set the idle to jump start transition.
Return to the Arms State Machine graph and drag a wire from the Idle state to the JumpStart state.
Double-click the transition to edit it.
Navigate to the My Blueprint panel, press Ctrl and drag off IsFalling variable to the Graph to create the Get Is Falling node.
Connect the output pin from the Get Is Falling node to the Can Enter Transition input pin of the Result node.
Blueprintcontext_graph
4.4.3 - Add Run to Jump Start Transition
During this step, you are going to set the run to jump start transition.
Return to the Arms State Machine graph and drag a wire from the Run state to the JumpStart state.
Double-click the transition to edit it.
Navigate to the My Blueprint panel, press Ctrl and drag off IsFalling variable to the Graph to create the Get Is Falling node.
Connect the output pin from the Get Is Falling node to the Can Enter Transition input pin of the Result node.
Blueprintcontext_graph
4.4.4 - Add Jump Start to Jump Loop Transition
During this step, you are going to set your jump start to jump loop transition.
Return to the Arms State Machine graph and drag a wire from the JumpStart state to the JumpLoop state.
Double-click the transition to edit it.
Right-click in the Graph, search for and select the TimeRemaining for 'FPP_JumpStart' node.
Drag off the Return Value output pin of the Time Remaining, search for and select the Less Equal node.
Enter 0.1 in the other output field of the Less Equal node and then drag a wire from the output pin of that node to the Can Enter Transition input pin of the Result node.
Blueprintcontext_graph
4.4.5 - Add Jump Loop to Jump End Transition
During this step, you're going to set your jump loop to jump end transition.
Return to the Arms State Machine graph and drag a wire from the JumpLoop state to the JumpEnd state.
Double-click the transition to edit it.
Navigate to the My Blueprint panel, press Ctrl and drag off IsFalling variable to the Graph to create the Get Is Falling node.
Drag off the output pin of the Get Is Falling node, search for and select the Not Boolean node.
Connect the output pin from the Not Boolean node to the Can Enter Transition input pin of the Result node.
Blueprintcontext_graph
4.4.6 - Add Jump End to Idle Transition
During this step, you're going to set your jump end to idle transition.
Return to the Arms State Machine graph and drag a wire from the JumpEnd state to the Idle state.
Double-click the transition to edit it.
Right-click in the graph, search for and select the TimeRemaining for 'FPP_JumpEnd' node.
Drag off the Return Value output pin of the Time Remaining, search for and select the Less Equal node.
Enter 0.1 in the other output field of the Less Equal node and then drag a wire from the Boolean output pin of that node to the Can Enter Transition input pin of the Result node.
Blueprintcontext_graph
4.5 - Associating Animation & Character Blueprints
During this final section of the tutorial, you are going to associate the animation Blueprint that you created with your character Blueprint.
Compile and save the Arms_AnimBP Animation Blueprint before closing it.
Navigate to the Blueprints folder in the Content Browser and open the BP_FPSCharacter Blueprint.
Select FPSMesh in the Components panel.
Click image for the full view
Set the Anim Class for the FPSMesh to the Arms_AnimBP Animation Blueprint you just created.
While you are in the Defaults mode, change the FPSMesh transform to {50, -15, -150} for Location and {0, 25, 350} for Rotation.
Click image for the full view
Click Compile and Save button before closing it.
Click the Play button in the Level Editor Toolbar.
Your arms will be animated as they transition through the animations that you hooked together in the Animation State Machine.
Congratulations! You've learned how to:
✓ Set-up a Project
✓ Implement a Character
✓ Implement a Projectile
✓ Animate a Character
You've just completed the C++ First Person Shooter tutorial!