Version
menu_open
Wwise Unreal Integration Documentation
Handling Sounds on Physical Objects

PostEvent and SetRTPC on Collision - PostEvent | SetRTPC

In the previous sections, we have covered how to play music when starting the game and from a specific time in the animation. However, some of your audio integration might require a better understanding of physics. In this next example, we'll play a sound whenever an instantiated object collides with something else.

To start, it’s recommended you create a simple system for instantiating objects in front of the character.

You can add this to your Character Blueprint. To create this 'Wwise Object' Class, create a new Blueprint Actor, add a Static Mesh component with a 1M_Cube Mesh, and enable Simulate Physics.

With this, an object will be instantiated in front of the character when you press the F key. When the instantiated object collides with any other object, we want to play a sound. For that we'll be using Unreal's OnComponentHit Event, which needs to be enabled on the instantiated object.

  1. Open the 'Wwise Object' Blueprint Actor, select the Static Mesh and enable Collision > Simulation Generates Hit Events.

    With this option enabled, we can create the OnComponentHit Unreal Event.

  2. Right-click Static Mesh, select Add Event > Add OnComponentHit.

  3. You can now connect this to a Post Event function and reference itself.

    However, if you press play now, you would most likely get blasted with sounds when colliding, since Unreal calls even minor collisions. As such, we will filter out all insignificant collisions and only post sounds when a forceful hit is detected. This detection needs to be performed before the PostEvent is called. To measure the force of an impact, you can reference the velocity of a physics-enabled object, get the magnitude regardless of the direction in which it may hit something, and then, if this is greater than a set threshold, you can pass on the call.

  4. From the Hit Component, get the length of the component's velocity. If it is above 40, allow the call to pass through.

    You should now get a much more pleasant sound representation when the object collides with other objects. However, there is still no variation in the sound itself, whether the object is hit forcefully or just above the threshold. To achieve this, we will forward the velocity to Wwise as an RTPC. This will allow us to influence the sound with a simple volume change or with Effects. The recommended setup in Wwise is a shown:

    For setting the RTPC, let's simply use the same Vector Length. However, keep in mind that you'll need to set the RTPC on the same Actor that the Wwise Event was posted on.

  5. From the Branch, create a SetRTPCValue function and connect it to the VectorLength of the Velocity.

Refer to this video for a walkthrough of playing sounds with a threshold based on velocity.


Was this page helpful?

Need Support?

Questions? Problems? Need more info? Contact us, and we can help!

Visit our Support page

Tell us about your project. We're here to help.

Register your project and we'll help you get started with no strings attached!

Get started with Wwise