Sound Materials - jgoffeney/Cesium4Unreal GitHub Wiki

Back

Reference

Setup

Create a level using the Third Person Template. This does not require C++ for a new project. I am using UE5 and will make the appropriate updates.

Sounds

You will need audio files for your footsteps. They are fairly cheap on the Unreal marketplace.

Setup Base Surface Materials

For each different surface create a Physical Material under Physics (not Materials) and give it an appropriate name.

Add Physical Surfaces

The project settings allows you to reserve a surface type for each physical material.

  • Under Project Settings->Engine->Physics->Physical Surfaces:
    • For each Physical Material pick an available SurfaceType and enter a name similar to the matching
    • I am using grass and gravel sounds so I used those names

Assigning Surface Types To Physical Materials

Open each physical material you created and under Physical Properties->Surface Type menu select one you just set up in the above section.

Grass

Update Level

Add a Floor

In the level editor duplicate the floor and position it so the character can walk on the different materials that will be applied to them. I made a copy of the floor, butted it up to the original and removed the separating wall.

Edit and Apply Material

  • Under Content->StartContent->Materials drag the texture materials matching your desired sounds to each floor (you may want to duplicate them). I picked M_Ground_Grass and M_Ground_Gravel.

  • Open each texture material for editing.

    • In the details under Physical Material->PhysMaterial select the Physical Material matching it.
    • In the video the author adds a UV material parameter which seems to be mainly for visual effect and thus optional.

Update Character

Add Animation Notifications

Animation notifications are like tags you can add to an animation's timeline and when you are reached they fire an event. When you create a new tag name Unreal will automatically generate a new blueprint event for it.

  • Open up the character run animation.
    • For Manny it is Characters->Mannequins->Animation->Manny->MM_Run_Fwd. You will also have to do this for other animations like walk.
  • Add Footstep Notifications
    • When you open the animation editor in UE5 you will see green L and R tags are already present on the timeline. These are apparently Sync Markers which are used differently. So I added a new track and then added a Footstep notify for each.
    • Add a new track.
      • Select the pulldown next to Notifies and select Add Notify Track.
    • Add notifications
      • At each location of the track you want to add a notification then right click and select Add Notify->New Notify and give it a name. At this point I used Footstep. You can use a different tag each time if you want to fire different events but I only want to track one event.

FootstepTrack

Edit Animation Blueprint

The general idea is on each foot step we will query the location of the character and check what material it is standing on. Then the appropriate sound will fire. Not that the LineTraceByChannel node is used for these tasks.

  • Open up the character's animation's blueprint.
    • For Manny it is Characters->Mannequins->Animation->ABP_Manny.
  • Open up the Event Graph and add a new event for footsteps.
    • Add the event to the graph under Add Anim Notify Event. For the notify Footstep the event is AnimNotify_Footstep. If you want to test if it is working then attach a Print String node to it.
      • Add a LineChannelByTrace node
        • Connect the exec pin from the event.
        • Start and End
          • Start is from the character location
            • Add a GetPlayerCharacter node attached to GetActorLocation to get the current Unreal location.
          • End is from a point below the character location.
            • From GetActorLocation output create Subtract node and set the Z value to something arbitrary (but positive) like 100.
      • The outputs are the boolean Return Value which is true on a hit and the Out Hit which is the hit object.
        • Using a Branch node on the Return Value makes the event graph continue only on a hit.
        • The Out Hit is connected to two nodes:
          • BreakHitResult supplies the hit location to spawn a sound.
          • GetSurfaceType to SwitchOnEPhysicalSurface selects which physical material was hit.
          • Using these pieces of information it determines which sound should play and where to play it.
      • Using FlipFlop nodes allows a couple of sound files to swap for each surface type.
        StepSoundGraph