In this tutorial we will learn how to implement multi-surface footsteps for a Third and First Person Character using Wwise in Unreal Engine 4.
Footsteps setup in the Wwise authoring tool
Let’s create a Switch Container with Random Containers representing the terrain surface types. Insert the footsteps audio files into the corresponding Random Container:
Switch to Game Syncs Tab and add a Switch Group to your desired Work Unity. For each Switch, add a child Switch to the Switch Group:
Go back to the Switch Container and select the Switch Group you created in the General Settings in the Group field:
Make sure to also define a Default Switch to avoid any errors in the game engine.
Now you can assign the Sound Objects inside your Switch Container to the Switches in the Switch Group by dragging and dropping the objects from the Contents Editor to the Switches (Assigned Objects) on the right:
Finally create a new Event and assign the Switch Container created in the first place as a target of the play action:
As a last step add the Event to your desired SoundBank (don’t forget to generate the banks!).
Footsteps setup in Unreal Engine 4 with Wwise
The first thing we want to do is to set up new Physical Surfaces in Unreal’s project settings. Go to Edit->Project Settings and select the Physics tab. In the Surface Type fields, enter your footsteps terrain types:
Create a new Material and a new Physical Material for each Surface Type:
Change the Surface Type in the Physical Properties settings of each Physical Material:
After that, open each Material and select the appropriate Physical Material in the Details tab:
Create a new simple level consisting of four floors and assign a material to each floor:
Implementing Footsteps for a Third Person Character with Wwise in Unreal Engine 4
Open the run or walk animation of your character and insert a new Animation Notifier at the keyframes in which your character’s feet touch the ground:
In the animation blueprint of your character, create a new reference to the ThirdPersonCharacter first by using the Cast To ThirdPersonCharacter node:
We want to cast a ray every time the Footstep Notify fires an event. For this we use the LineTraceByChannel node and connect it to the AnimNotify_Footstep node. We get the socket location of our root bone by using the Get Socket Location node and assign it to the Start vector of the line trace node. For the End vector, we use the Vector – Vector node and subtract (0, 0, 100) from the socket location, so that the ray fires in the direction of the character’s feet. We add the character reference to an Array and connect it to the Actors To Ignore field. After that we use the Break Hit Result node to get information about what the ray actually hit. We also check if the ray hit anything using the Branch node:
We create the Switch on EPhysicalSurface node and connect it to the Phys Mat property of the Break Hit Result node. We create a new string variable called Switch State and set the value of that variable fir each physical surface. We use the Spawn Ak Component at Location node to spawn an Ak Component at the foot root location after setting the a switch state. We get the return value of that node and pass it to the Set Switch node to set the switch before posting the Event. Make sure to insert the corret Switch Group in the appropriate field. After that we post the footsteps Event by using the Post Associated Ak Event node:
Implementing Footsteps for a First Person Character with Wwise in Unreal Engine 4
If we are working on a simple First Person Character, it may be the case that our character doesn’t have any animations in which we can add Animation Notifications. We can still implement footsteps sounds in this situation by checking if the player is moving and playing the sounds based on an interval of time.
In the FirstPersonCharacter Blueprint, create a new boolean variable named isMoving. Get the velocity of the Actor by using the Get Velocity node and check if the Vector Lenght of the returned velocity is greater than 150. If that is the case, set isMoving to true and use the Set Timer by Event node to fire the custom event PlayFootstep. Make sure to check the Looping option and set the time to something between 0.3 and 0.8 seconds depending on the speed of your character. Create an additional Branch node that sets the moving variable to false and clears the timer if the velocity is less then 150. Connect the two Branch nodes to the Event Tick node and to a Branch node that checks for isMoving as seen here (click to open in a new window):
Essentially, we can copy most of the previous implementation to this Blueprint and just connect the custom PlayFootstep event to the LineTraceByChannel node:
Instead of getting the root bone location of the feet, you can get the actor’s location, so you can pass it to the Spawn Ak Component at Location node. That’s it! Start the level and you should be able to hear the footsteps sound playing based on the terrain you walk on.