Character States in Unreal Engine

Introduction

I will be importing character animation cycles for this blog. I will also need to use character blueprints where I can easily access and add sound effects. I have imported in the ninja cycle animation work to use for this blog.

First, after importing my animations into Unreal Engine – highlight the animations and create a sprite. This will create a flipbook and an animation for the character. It is important to remember the frame rate we need to design the animation in, for this example we need to use 25 frames/s.

The canvas size must be kept the same for each animation state. Here there are a lot of different animation states.

In the second side scroller character folder, I will need to change the idle animation scale down as they are too big.

The animation here has been updated to make it easier to switch between states.

An enumeration is a list of different named values that we can find by right clicking on the blueprint tab. I will then need to name it and load it. On the menu I will add new states and change their display names. Different states that I could add could be attack animation, for example.

We set up the idle state first. Unreal has already provided us with something we can find by searching up ‘ismoving’.

I can tick the check box to make this blueprint into a variable, this with turn it to a true or false state.

Using the blueprints, we can make it so if the character is moving it will have a new animation. I have to further decide whether that animation will be a run or a walk animation.

I needed to use a something called a print string for this, then use the Is ninja moving variable to plug into the string.

If we go to settings at the top > project settings, I can find the key binds to control the character. I have to use the action map so that I can select the actions I want, I will add the right key bind for the right action.

I am able to add more than one key bind for the same action if I click on the plus icon on the right. We need to set up a new ‘Boolean’ called ‘Is running and use this on a new InputAction Sprint.

Select the Is ninja sprinting box for pressed.

The default unreal speed is set to 600. We need to set the speed to 150, we need the sprint to obviously speed the character’s movement up. We can set the characters top speed in character movement.

I will change the set speed on max walk when pressed then walk and add another set max speed for walk, set the values and link it. To get the set speeds we need to drag out from the character movement.

I created a delay on the jump and set this delay to 1.5 seconds. Next I need to set up my jump function. I basically need to recreate what I have done, but for the purpose of my jump animation. However this is different, the player wont hold the space (jump) button for the whole duration of the jump. Unreal engine has a jump already set up and I can use and edit.

We created a flipbook for the output.

We have to put in the movement states.

This shows us our saved list of animation flip books

Assigned each option to an asset.

Booleans always need branches when being used.

I need to set this up for sprinting and walking, and idle, this means if none of the Is variable checks are active, the default animation will be set to idle until the player does anything. This uses the Booleans to determine the characters state.

Need to create a flipbook for them.

Plug the sprite in for the animations:

Audio effects and music

We first need to find the audio we want to use from YouTube. In this case, we can use ninja-inspired music and some intense battle music. We need to download the audio to be able to edit it in Adobe Audition.

We look for a combination of music and sound effects such as jumping or walking on metal etc.

We need to extract out the footsteps first. We zoom into the audio’s timeline and select a small portion of the audio. We copy this and go to file > new > audio file.

The sample needs these settings:

We can change the bit rate to either 16 or 24.

We can paste the copied part of the audio into a new layer. We carry on this process until we have around 4-5 footstep sounds.

The sample rate needs to be 44400hz.

Once complete, we can go to the first footstep and export it. It needs to be a wave PCM file.

After this, if we double click the next audio layer it should remember the export settings such as location and file type.

The small square at the top left can be dragged in to add a fade effect to the audio. These squares can be found on both sounds of the audio track. Fading the audio helps it blend better in a loop.

For the more intense music file, we need to edit it similar to the first file. After playing about with the duration of the file and when to end the loop, we add a fade the same as the last file and export it with the same settings.

We can test other ninja sound effects that we have saved, such as the gong sound effect played at the start of the audio file, perhaps before the music to act as an introduction. If our audio is ever too loud and reaches the red area, it will begin to distort the speakers – therefore it is important to keep it between green and yellow.

In UE, create a new folder and import in the audio files we edited in Adobe Audition.

To get the introduction music to start, we can layer the audio with other audio files or just play it alone. However, we will be doing it via an audio cue. We can use a mixer in the audio cues to simultaneously play two times of audio files.

We want the gong to play first, so in our blueprints we can add a audio delay. Our maximum audio delay for this example can be 3 seconds, so the gong plays before the music kicks in.

We can also make it so an audio file plays every ‘x’ amount of seconds, such as every 30 seconds. We tried to add this effect to the gong sound effect, but in my opinion, it became annoying pretty quickly and sounded better at the beginning alone.

We add another pin to our mixer to link a new audio file to it, such as the ninja voice sound effects. This is set to play at the same time as the gong before the music starts, and this lets the music play out on its own.

Save the audio cue and title it appropriately before any progress is lost.

We can have the audio file playing on loop in the background of this level. But lets say we wanted to have a boss fight at the bottom layer of the level, we will need to add an audio cue for the more intense boss music to play.

In the level blueprint, right click and select add collision event (trigger box). Add a fade out audio component and link it to the trigger box. For this test, we can set the audio fade out to be 3 seconds. The goal here is to make it so that when a player enters a select area, the audio fades on cue and plays another sound file.

CONCLUSION

We had some struggle at the end getting the audio cue to work but I understand the goal Gareth was trying to achieve. In the end, he got it working successfully. This workshop was tricky at times, as well as straightforward. I think I most understood the audio editing part of this.

Leave a comment