Using sound effects

Now that we have the Artifact, tentacles, and animation working in our level, we could just stop there and call it done, right? We could, but wouldn't it be more fun give the player an opportunity to strike back at the dark power that has taken over our space station? Let's blow that Artifact up!

Before we just jump right in, we need to plan this out a bit. This will help us be able to think through the programming logic of the blueprint sequence and plan out how to build the explosion. So what goes into a great video game explosion? Well there has to be sound. Without a good solid explosion sound, any attempt at this will fall flat. We also need fire, smoke, and chunks to really make it shine. There has to be some type of instigating event, such as time, player interaction, or damage. Lastly, a rough sequence of events might be event, sound, explosion particle, smoke particle, delete object, and chunky particle. This way the smoke, explosion, and chunky particle effect will cover when we delete the exploding asset. Just our luck, Unreal has most of those pieces in the Starter Content folder!

Let's start prepping for our explosion within our class Blueprint by adding the sound effects and setting them to trigger when we need them.

Using sound effects

Turn off Auto Activate in the Details panel

Tip

Sounds can be imported into Unreal in the same we have imported other assets. If you feel the Starter Content sounds don't fit for your explosion, feel free to search for Royalty Free sounds. These are sounds that can be used in your projects for either free or a small upfront fee. Royalty Free means that beyond the initial payment, there is no further payment required.

  1. Adding sounds to our class blueprint is similar to adding any other type of component and can provide some real depth to our explosion. In the Class Blueprint editor, click the Add Component button and select Audio from the list. Next, with the audio component selected, head to the Details panel and find the Sound option. Here, you will find a field where we can assign a Sound Wave or a Sound Cue by selecting it in the Content Browser and then clicking the small arrow. Alternately, you can select the sound you want to use before clicking the Add Component button, and Unreal will add the selected sound. Let's make this one the Explosion Cue. To make sure it only goes off when we want it to, select it and head to the Details panel. Find the Auto Activate option and turn it off.

    Tip

    Tip: The difference between a Sound Wave and a Sound Cue is very similar to the differences between Textures and Materials. Sound Waves make up Sound Cues, along with a few special Blueprint nodes. Double-click the Explosion Cue and take a look!

  2. Time to add on a bit to our Artifact's programming! I know, everyone gets excited about this part. Let's add a bit of fun to our explosion and add a countdown clock.
    Using sound effects

    Programming the countdown clock for the explosion

  3. We will branch this functionality off the event on pressing E using a Flip Flop node.
    Using sound effects

    Connect the countdown to branch B on the Flip Flop we created earlier

  4. Back in Chapter 2, Starting Our First Project, we used a Flip Flop node to control our cargo elevator. Essentially, the node will do branch A and then branch B, alternating between them. We will use it to allow the E key to first open the Artifact and then allow the player to place a bomb and start a countdown. Head over to the search box in the Palette panel, search for Flip Flop, and drag one into the Blueprint window. Break the connection between the E event and the Do Once node, and connect it up as shown in the preceding image.
  5. Let's create the countdown. For this feature, we will use the Print String node to print out a 5-second countdown before we trigger our explosion sound.
    Using sound effects

    Program the Print String nodes in the countdown

  6. To start, we will need a Delay node and a Print String node. Both of these can be found using the search box in the Palette panel. For the Delay node, go ahead and leave the Duration at 0.2. Change the In String option on the Print String node to read Explosives Armed: 5. Left-click and drag to select both of these nodes and copy/paste them. On these new nodes, change the Duration on the delay to 1.0 and the In String on the Print String node to Explosives Armed: 4. Repeat the process three more times to complete the countdown. The last node in the sequence is the Activate node. Since we turned off the Auto Activate option on our Explosion Cue, this node will activate the component and play the sound. With all of our pieces now in the Blueprint window, connect them together just like the preceding image.
  7. Save and compile our class Blueprint. Save your level and press Play to test it!

Now that we have our sound effect working, there are only a few move steps to complete our explosion. However, there are a lot of other opportunities for using sounds in this Blueprint. For example, we could add an opening sound to the Artifact, or some eerie music to play while it's open. Experiment and see how you can use sound to further enhance the mood!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.93.175