Dynamic Car Engine in UE4

Checked with: Version 4.10  13/01/2016

In this video we’ll create a vehicle sound using engine loops and autopitch modulation. We’ll also use Blueprint to generate parameter values to drive our sound.

 

Download FMOD Studio for UE4 and the tutorial assets from the Downloads Page

   

Transcript

(0:00) Hello and welcome to the FMOD Studio and Unreal Engine 4 tutorial series.  My name is Sally Kellaway and you’ve joined us for the sixth video in the series, where we are going to design a vehicle engine.

(0:15) Now, we’re just going to recap on some of the things that we’ve already got in our level.  We have a fully fledged ambience and 3D twister sound implemented in our level.  And we also have a very good understanding of parameters and snapshots from our character workshop.  From our Snapshots workshop – which were our previous two videos in the series.

(0:35) Now, today we’re going to design and implement a dynamic vehicle engine sound that responds to RPM and load and a dynamic tyres through sand sound that also responds to the parameter (but, this parameter is speed).  So, we’re going to set up all three parameters that we will be updating all the time.

(1:00) So, in FMOD, grab a new folder and call it car (so we can save all of our assets in an organised way).

(1:08) Now, create a new event and call it “tyres rolling” and we’ll create two more events at the same time – “Engine” and “Engine Total”.

Create the three events for the Vehicle, and house them in their own folder.

Create the three events for the Vehicle, and house them in their own folder.

(1:24) We’re going to look at the tyres rolling sound first because it is the easiest to set up in Studio.  What we will do is we will open our Audio Bin window and search for our rolling sound, and drag and drop that straight in to the Tyres Rolling event.

(1:38) …and then we’ll just pop on the loop button, and then set a new loop region around the event as well.

Setup of the Tyres event - Region and Loop Region

Setup of the Tyres event – Region and Loop Region

(1:49) We’ll zoom right in with the birdseye view, and then we’ll add the “Speed” parameter (Click on the Plus tab next to the Timeline Tab) – so we need to add a custom parameter here, with the range of 1, up to 3000.  (When we set up all of our sounds in our Completed project we were able to work out that the speed of the buggy goes all the way up to 3000).  You can normalise this value so it goes between 0 and 1, but this is not critical, so we will move on.

(2:25) We’ll add some automation to the volume (Right-click on the Volume dial in the track header), as we don’t want the tyres sound to be coming through when the car is not actually moving.  So, we’ll just add a really sharp fade in on that automation and we might just turn the overall volume down a little bit and then have it turn up to when you’re going really fast.

(2:46) One more thing that we will so is we will add some pitch automation – in the Event Macros tab – right click the Pitch knob.  When you right click, press “add automation” and we’ll add maybe 5 or 6 steps up as you get faster and faster.

Once a Speed parameter is added, create Volume and Pitch automation for the Tyres sound.

Once a Speed parameter is added, create Volume and Pitch automation for the Tyres sound.

(3:08) And we’ll also double check our minimum and maximum distance, to ensure our 3D sound properties are accurate.

(3:15) Audition the sound and make tweaks if you need to.  Just make sure you’re turning the Speed parameter to get some volume through.

(3:33) So, we’ll just assign this to the Master Bank and then we’ll move on to the engine sound.

 

(3:37) For the Engine Event, we’ll need two tracks – “On Load” and “Off Load”. Create a second track by right-clicking on the existing track and selecting “Add Track”.

Create On Load and Off Load tracks in the Engine Sound Event.

Create On Load and Off Load tracks in the Engine Sound Event.

(3:44) Before we drop any assets we are actually going to add the parameters we need.

(3:52) We’ll need add the RPM parameter between 1000 and 10 000

(4:00) And we will also need a Load parameter between -2000 and 2000.

(4:11) And we’re actually going to drop our assets into the RPM parameter, because an engine’s sound changes over the RPM range as opposed to over time.

(4:28) Open the audio bin and we’ll grab some assets; So, the “Idle” goes in the “Off load” track

(4:37) “On Idle” in the “On Load” track.  We’ll pop the “Limiter” in both of the tracks.  And then what we will do is we will put the “On Load” assets in the “On Load” track, and the “Off Load” assets in the “Off Load” track.

Baja Truck Assets from the Audio Bin arranged in the right order, in the right tracks.

Baja Truck Assets from the Audio Bin arranged in the right order, in the right tracks.

(5:15) Now, just close off the audio bin, and what we’ll do with all these assets is switch each to being a looping asset (select reach module and in the Deck area, hit the loop icon), and then we will set the length of each of the regions.

(5:55) The crossfade regions start and stop at the following RPM points;

  • Low – 2000 up to 4500
  • Mid – 4000 up to 6000
  • High – 5500 up to 8000
  • Limiter start at 8000 and extends all the way to the max of this parameter.

(6:30) And then we will do the same for the “Off Load” track.

  • Very low – 1500 up to 2500
  • Low – 2000 up to 4500
  • Mid – 3500 up to 6000
  • High – 5500 up to 8000
  • Limiter is the same – starting at 8000 and up to maximum.
Assets arranged with correct module widths for each module.

Assets arranged with correct module widths for each module.

(7:30) If we were to listen to this right now, it would just be fading between each of these static regions in terms of pitch.  What we can do is add some Autopitch modulation and set the root pitch of each region to get an automatic pitch sweep and matching between each of the assets so the engine sounds smoother.

After selecting each region individually, add the Autopitch modulation.

After selecting each region individually, add the Autopitch modulation.

Set the root pitch of each module individually.

Set the root pitch of each module individually.

(7:53) The root pitch of each of the modules are;

  • Idle On Load – 1800
  • Low On Load – 3500
  • Mid On Load – 5000
  • High On Load – 7000
  • Limiter On Load – 8000
  • For the Off Load Track…
  • High Off Load – 7000
  • Mid Off Load – 5000
  • Low Off Load – 4500
  • Very Low Off Load – 3000
  • Idle – 1000

(10:10) What we’re going to set up is the Load parameter to have a volume automation to switch between the two. So, On Load will only be audible when the parameter value range is in the positive range.  And then Off Load will only be audible when it’s down in the negative range.

(10:40) And then from here, we just need to add a crossfade.  If you find that you are losing too much volume in the crossfade, just fix up the curve to maintain equal volume across the RPM range.

Volume automation to switch between On and Offload tracks.

Volume automation to switch between On and Offload tracks.

 

(12:20) One thing that we will set up before we jump in to Unreal is Seek Speed – slowing on our Load parameter so if the values change quickly or jump around the values will be smoothed and the transition between On Load and Off Load is still super smooth.  When we set a seek speed, we’re applying a slower speed of movement to the parameter as it changes.  Even if it’s changing in real time or game time, we’re able to slow down the rate of change of the playhead here in FMOD so that we don’t end up with choppy changes in the sound of the engine.

(13:07) What we need to do is select the Load parameter tab to gain access to the Seek Speed and just type in the value 5000.

Setting Seek Speed to 5000 can be done in the Effect Deck area.

Setting Seek Speed to 5000 can be done in the Effect Deck area.

 

(13:33) And what we’re going to do now is house our Engine event in our Engine Total event, and then we will be ready to jump back in to Unreal.

(13:47) Open up the Total Engine event in the Event Editor window. Open the Audio Bin and grab the “startup” asset, and drag and drop this straight in to the Total Engine Event.

(13:49) Then, open up the Event Browser.  This window is a list of all of your events, almost exactly the same as how they appear in the Event Editor window. So if we drag and drop the Engine event in to the Total Engine Event, we can automatically create a cross fade between the engine start up and engine sounds by dragging the Engine sound over the end of the Startup module. Adjust the cross fades to achieve a smooth transition between the sounds.

Drag the Engine Event from the Event Browser to the Total Engine Event.

Drag the Engine Event from the Event Browser to the Total Engine Event.

(14:28) Now we need a way to tell this Engine event to continue looping. What we will do is create a Sustain Point in the logic track, which will catch the playhead and keep looping at the Sustain Point.

Add a Sustain Point to loop the Engine sound.

Add a Sustain Point to loop the Engine sound.

 

(14:57) All we need to do now is just add in our RPM and Load parameters (as they appear in the original event) and then the parameter information will be sent through to the sub-event – the Engine sub-event.

(15:27) Just make sure that all your new events are assigned to the Master Bank.  We’ll hit save and build and jump straight in to Unreal to implement these sounds.

 

(15:40) What we need to do is open up the FMOD Buggy blueprint, and we need to set up a few things before we start going crazy in our blueprint.

(15:52) So, we remember from our Twister blueprint, that we wanted to attach the sound to the Object as a component because we wanted the sound to follow the Actor around in the level.  So, we’re going to jump over to the Components view to do the same with our Tyres and Engine sounds.

(16:03) We’re going to click here and add an FMOD Audio Component and we’re going to name it “Tyres sound”.

You will need to create two new Audio Components for the Vehicle sounds.

You will need to create two new Audio Components for the Vehicle sounds.

(16:26) Then, attach the sound event in the Details panel down here.  Just type in “tyres rolling” FMOD event, and we’re going to do the same for the engine sound.

Assigning the FMOD Events can be done in the Details panel on the Right.

Assigning the FMOD Events can be done in the Details panel on the Right.

(16:51) Select the Engine Component and switch Auto-Activate off.  We only want to cue this sound to start when we switch in to the car.  Because we have the Engine Total sound with the startup sound and Engine sound that loops with a Sustain Point, we can cue that off whenever the player hits the “E” to switch in to the car.

Ensure Auto Activate is switched off for these events.

Ensure Auto Activate is switched off for these events.

(17:18) Head to the Blueprint Graph.  We can now activate the sounds we’ve just attached.  The next few things we are going to do is set the RPM parameter, then set the Load parameter, then set the speed parameter for the Tyres.

(17:54) So let’s start by activating the Engine sound.  The way that we are going to do this is by looking for a module called “Event Possessed”.  So, this is going to tell us when the actor has been possessed, we want to get the Engine Sound, and then play the Engine Sound.  So, here I’m grabbing the FMOD Play Audio component right here, and we’re just going to hook those together.  And that’s all we need to do to activate the Engine sound.

Blueprint code for Activating the Total Engine Sound Event.

Blueprint code for Activating the Total Engine Sound Event.

(18:31) I’m going to house this function in my comment box so my graph is tidy.  We can now hit Compile and Save and that we can move on to setting the RPM parameter.

(18:41) We’ll start with the “Event Tick” – this module gives us the internal game time that we can use to track and update our parameters.  We will also need to grab the Engine sound Component itself and also the Vehicle Movement component.  Having all these components to help us Send, Get and Set information to help us power our Engine sound.

Grab the Event Tick, Engine Sound Component and Vehicle Movement Component to start constructing the RPM parameter.

Grab the Event Tick, Engine Sound Component and Vehicle Movement Component to start constructing the RPM parameter.

(19:11) From the Engine sound, click, drag out, and release to search for “Parameter”.  Here we have the option for an FMOD component called “Set Parameter” which is exactly what we want.

Getting the Set Parameter node from the Engine Sound Component.

Getting the Set Parameter node from the Engine Sound Component.

(19:20) So we have to set the name of the Parameter now, type it in exactly as it appears in FMOD, this field is case sensitive so we need to be careful.

 

(19:32) Next step is to get the Engine Rotation Speed (which is our RPM).  From the “Return” field, hook this up to the Set Parameter Module and hook the “Event Tick” in to the white arrow up top so that the setting of the parameter happens every Event Tick.

Getting the Engine Rotation Speed from the Vehicle Movement Component.

Getting the Engine Rotation Speed from the Vehicle Movement Component.

(19:55) So there’s the RPM parameter all ready to go.

The Engine Rotation Speed can be linked directly to the Value component of the Set Parameter module.

The Engine Rotation Speed can be linked directly to the Value component of the Set Parameter module.

 

(19:58) Now we will set the Load parameter.  This one requires a little bit more scripting.  What we’re going to do is grab the Engine sound component again.  You can use the same Engine and Vehicle components instead of making new ones but to keep our graph tidy and easy to read I’m grabbing new ones for each step of my Blueprint code.  This helps avoid connecting lines everywhere looking like spaghetti!

(20:34) We’re just going to set the load parameter again.  So grab the “FMOD Set Parameter” module again and remember that the parameter was named “Load”.

(20:42) And next we’re going to use the Vehicle Movement Component to get the information that we need for this parameter value. 

Grab your components for the calculation and assignment of the Load parameter.

Grab your components for the calculation and assignment of the Load parameter.

(20:52) In addition to these components, we need to work with an additional “Speed” variable.  We have already created and packaged in this variable with this project so that we can calculate and store this speed value to use in the calculation of Load.

In Unreal, you can create Variables to store values with.  This is done on the Right Hand Side of the Window.

In Unreal, you can create Variables to store values with. This is done on the Right Hand Side of the Window.

(21:06) The first step is to set the LAST Speed that was recorded in the game.  Grab a connector off the Set Parameter module and “Set Last Speed”. Do remember to hook the last module up to this Set Parameter module.

You can link the Set Last Speed variable node to the Set Parameter node.

You can link the Set Last Speed variable node to the Set Parameter node.

(21:20) We’re designing logic to get the Speed from this parameter saved in a variable that will feed back in to an equation we will create.  With the goal of calculating our Load parameter, we will be calculating the rate of change of the RPM parameter.  So, a high load will occur when the engine RPM increases very quickly, and a negative load value occurs when the engine RPM is decreasing.  We won’t be able to tell if the RPM is changing unless we store the value, which is the reason for this variable.

(21:55) From the Vehicle Movement component, we need to grab the Engine Rotation Speed again and we feed the output of this in to our Last Speed variable.  This value will be stored every Event Tick and the next part of the Blueprint will take this value and use it for comparison.

Get the Engine Rotation Speed, and use this as the input to Set Last Speed.

Get the Engine Rotation Speed, and use this as the input to Set Last Speed.

(22:16) Pull another connection from the Return value of the Engine Rotation Speed and when you release the mouse button, search for the “subtract” sum – for the “float – float” option.

To get a rate of change, we need to Subtract the Last Speed from the Current Speed.

To get a rate of change, we need to Subtract the Last Speed from the Current Speed.

(22:30) First we Get the Last Speed, then we’ll use this Last Speed in this sum. So what we’re doing is subtracting the Last Speed from the current Engine Rotation Speed.  And save that current Speed in to our Last Speed variable to use in the next iteration of the loop.

(22:54) To apply this as a rate of change, we head back to our subtraction sum.  Grab a connector off the output of the sum and search “Divide” – the Float / Float option.

To apply this difference in speed to Time, grab a Divide sum...

To apply this difference in speed to Time, grab a Divide sum…

(23:12) And then we need to hook the Delta Seconds module in to the denominator.

Change over time is calculated by incorporating the Delta Seconds.

Change over time is calculated by incorporating the Delta Seconds.

(23:20) The output of this sum is the Load, so we can connect that straight in to the “Value” field of the Set Parameter module.

The output of this sum is the Load.

The output of this sum is the Load.

(23:25) So that’s all of the Load Blueprint, and we’ll just box it up so that we know what it belongs to.

 

(23:30) All we have to do now is set the Speed parameter for the Tyres.  This time we need to Get the Tyres Sound Component. From here we set the parameter, using the FMOD command of course.  This time we are setting the “Speed” parameter. Then drag the connector from the “Set Last Speed” module and connect that to our “Set Parameter” module.

(24:04) We’ll need to grab the Vehicle Movement component as well, but this time we’re getting the “Forward speed”.  Instead of using the speed the engine is revving at, this time we are getting the speed the Vehicle is moving.

The Speed parameter for the Tyres Sound will use the Forward Speed from the Vehicle Movement Component.

The Speed parameter for the Tyres Sound will use the Forward Speed from the Vehicle Movement Component.

(24:26) We then need to make this value an absolute number – so turning any negative numbers in to positive numbers.  Because we would also like to use the speed if the vehicle is reversing.  So, with the Return Value, type “absolute” to get this function.

To translate all values to the Positive Range, grab the Absolute node.

To translate all values to the Positive Range, grab the Absolute node.

(24:42) Then we just connect the output of the ABS function to our Set Parameter module and the Speed parameter calculation is all ready to go.

The output of the Absolute function is the input to our Speed Parameter.

The output of the Absolute function is the input to our Speed Parameter.

 

(24:48) Save, compile and audition the Engine.  Just hit play to start the game, and the “E” key to switch to the car.  You hear the engine startup sound, the engine event itself, which sits in a loop and then we can drive around.

(25:33) There’s a few more items to look at before we complete this tutorial, we’ll fix up the volume of the Engine sound, and offer you a few other suggestions about other changes elements that you can continue working on.

(25:54) My first observation is that we can take another look at the 3D Minimum and Maximum distance for the Engine event.  With the camera backed off from the car, this may have been one of the reasons it was a little quiet.

(26:00) So let’s change the Minimum Distance to 2 units, and the Maximum to 200, because even though it’s not a huge car, it’s still pretty loud and we want our human character to be able to hear it in the near vicinity.

Check your 3D properties of the vehicle so that you can hear the Event within the appropriate ranges.

Check your 3D properties of the vehicle so that you can hear the Event within the appropriate ranges.

(26:13) If we save and build we’ll hear those changes in the game.

(26:39) We are out of time in this tutorial, but there are a few refinements that you can make in your own time.

(27:03) Create a “Vehicle” mixer group;

  • Include the vehicle in the Twister snapshot
  • Include the Car in the Reverb as well.
    • Remember to scope in the “car” group and
    • Send signal from the “car” group to the Reverb return
  • Create a Snapshot called “Character mix” for when you are possessing the character
    • To duck out the Tyres Rolling
    • And add in the Breathing

Further development of the sound events

  • Balancing between the Engine’s Off and On Load tracks
  • Shifting the assets in the Engine event to smooth the engine “shifting gears”
  • Tuning Seek Speed on the RPM parameter
  • Fine tuning the Tyres Rolling sound

Credits and Attribution

Assets in the asset pack are provided by the Sound Librarian, Soundwave Concepts, Mixamo, Epic Games and Sally Kellaway by herself at Firelight Technologies. Please refer to the Read Me document for further information on licensing, attribution and commercial distribution.