Version
Wwise Unreal Integration Documentation
|
So far, we have built everything directly in our level, using prebuilt actors or adding components to individual actor instances. It's also possible to use the various spatial audio components to construct a Blueprint actor that can be replicated throughout the level. In this section we will build a replica of the structure from section Unreal Project Preparation, using a Blueprint class so that it can be easily added or spawned throughout the world.
Note: The Preparation for the Spatial Audio Tutorials must be completed prior to starting this tutorial. |
AkLateReverbComponent
and AkRoomComponent
rely on containment tests to check whether a given game object position lies within their parent PrimitiveComponent
. Simple collision is used for this check. You should therefore use a parent PrimitiveComponent
that has simple collision. For example, you could use a box collision, sphere collision, or capsule collision component. If the PrimitiveComponent
has no simple collision, the containment test will simply use the component bounds, which may be less accurate.
It is also possible to add simple collision to a mesh asset in Unreal (see Setting Up Collisions With Static Meshes). However, for complex meshes, such as those with doorways and openings, it is sometimes necessary to 'use complex collision as simple' in the collision settings for the mesh (see Simple versus Complex Collision). For example, this setting might be required to allow a character to enter a room through a doorway but still collide with the walls. When this setting is used, the containment tests for AkLateReverbComponent
and AkRoomComponent
will fail, as the simple collision will be ignored, and the mesh's full trimesh will be used. The simple collision tests used by AkLateReverbComponent
and AkRoomComponent
do not support trimeshes. For that reason, the recommended setup in a Blueprint class is to have a simple collision component as the parent when using AkLateReverbComponent
component and AkRoomComponent
. For example, the simple collision component could be a box, sphere, or capsule. If you have a specific mesh for a room or building, the simple collision component(s) could be added to the mesh as a child component(s).
Note:
|
Click on the new static mesh component and select the mesh in the Details panel.
Note: Automatic assignment of rooms to portals only works for convex meshes. Concave meshes (for example, L-shaped rooms) do not produce accurate portal room intersection. |
At this point, all of the box collision components are positioned in the same place; on top of each other. We'll reposition, scale, and rotate them so that they align with the rooms and doorways. The easiest way to do this is to use the Orthographic view. (The following steps are specific to the SpatialAudioDemoMesh, but similar steps can be performed for other meshes.)
Note: When aligning rooms and portals to the mesh in this tutorial, don't worry if they're not perfectly aligned or centered. Just be sure to roughly cover the correct areas. When designing a real environment, you can use the Transform section of the Details panel to input exact values. |
In the Viewport tab, click Perspective and change the view to Top.
Scale BoxRoomLarge along the x and y axes until its size matches the dimensions of the large room. (You can switch to scale by pressing R or selecting the Scale widget in the Viewport tab).
Select BoxRoomSmall and scale it along the x and y axes until its size matches the dimensions of the small room.
Select BoxPortalInner and zoom in on the wireframe until you see the extents of the inner doorway on the mesh.
Move BoxPortalInner to the middle of the doorway and then scale it along the x-axis such that it covers the extent of the doorway.
Select BoxPortalOuter and rotate it so that its local y dimension is pointing out of the doorway.
Note: This is necessary because portals have front rooms and back rooms which are automatically assigned by detecting the closest intersecting room along the portal's y dimension. In the case of the BoxPortalOuter, the 'back' (in local coordinate space) will be connected to the small room in our mesh, and the 'front' will not be connected to any room. |
Rotate BoxPortalOuter around the z-axis by 90 degrees. This can be achieved by typing '90' into the z-axis Rotation text box in the Transform section of the Details panel.
In the top view, ensure all rooms and portals are aligned with the mesh, as shown:
Select BoxRoomLarge and BoxRoomSmall and scale both along the z-axis so that they match the dimensions of the room.
Select BoxPortalOuter and BoxPortalInner and move them down to the center of the doorways, then scale them along the z-axis so they match the dimensions of the doors.
We will now add AkRoom components to the rooms, and AkPortal components to the portals.
For each box collision component, create a room or portal component (as appropriate) with a name similar to the parent. The result should be as shown:
Note: AkRoomComponent and AkPortalComponent are generic components that can be added to any primitive component. See AkRoomComponent and AkPortalComponent for more information. |
To confirm that the portals have valid placement, select the Visualize Rooms and Portals option in the Wwise User Settings.
Lines are now drawn between connected rooms and portals. If portals have invalid placement, they will be visualized in red.
Note: A portal has invalid placement if it is not connected to any room, or if the same room is connected to both sides. See AkPortalComponent for further information. |
The last two items to add to the Blueprint class are AkGeometry and AkLateReverb components.
Add an AkLateReverb component to the BoxRoomLarge box collision component.
The Blueprint class is now ready to use. We can drag an instance of the class into the world.
Position it beside the existing building.
Confirm that rays pass through the portals correctly in the new Blueprint structure.
Open the Level Blueprint and add logic to play the Play_LargeRoom_BP sound when the B key is pressed (see Unreal Project Preparation).
This section shows how simple collision and complex collision can be combined for the same mesh, such that Spatial Audio containment tests are performed using the simple collision, and Unreal queries make use of the complex collision.
Note: This section is based on the 'SpatialAudioTutorialMap' and the assets found in the ComplexRoomDemo directory in the WwiseDemoGame project, which is available from the Audiokinetic Launcher. The pre-made mesh assets and a custom Blueprint class are used to combine simple collision and complex collision. |
For complex meshes, such as those with doorways and openings, it is sometimes necessary to 'use complex collision as simple' in the collision settings for the mesh (refer to Simple versus Complex Collision). For example, this setting might be required to allow a character to enter a room through a doorway but still collide with the walls. When this setting is used, the containment tests for AkLateReverbComponent
and AkRoomComponent
fail because the simple collision is ignored and the mesh's full trimesh is used. The simple collision tests used by AkLateReverbComponent
and AkRoomComponent
do not support trimeshes.
One solution to this problem is to create two duplicates of the same mesh asset, using simple collision for one, and complex collision for the other. In the SpatialAudioTutorialMap, there is a complex room structure that demonstrates this technique.
To begin, test the complex room structure by playing in editor and walking around the building:
The rest of this tutorial demonstrates how the building structure is configured to handle simple collision for Wwise Spatial Audio containment tests, as well as complex collision for Unreal physics containment tests.
In the context browser, browse to WwiseAssets/SpatialAudioDemo/ComplexRoomDemo.
This folder contains two Static Mesh assets: Building_Complex and Building_Simple.
Open each of these assets and scroll to the collision settings in the Details Panel.
Notice that they have different values for their respective Collision Complexity properties.
Building_Complex has Collision Complexity set to 'Use Complex Collision As Simple' which means Unreal will not generate any simplified geometry for this mesh, and will instead use the entire trimesh. This is what allows the character to walk through the doorway opening. Building_Simple has Collision Complexity set to 'Use Simple Collision As Complex' which means Unreal will generate simplified geometry and ignore the trimesh. This is what allows Spatial Audio to perform containment tests for room containment.
Note: It is possible to set Collision Complexity to 'Simple And Complex'. However, this causes Unreal to use the simplified geometry for collision queries, which means the character cannot enter through the doorway opening. Instead, two identical meshes can be used - one with complex geometry and one with simple geometry. |
The next step is to combine both meshes inside a custom Blueprint class.
This Blueprint uses two Static Mesh Components that are positioned right on top of one another.
For the StaticMesh_Simple component, 'Visible' is disabled and 'Hidden in Game' is enabled in the Rendering section. This is because this mesh is only used for its simplified geometry, so that containment tests can be made for Spatial Audio.
Also for the StaticMesh_Simple component, the Collision Presets property is set to 'Trigger'. The simplified geometry creates a barrier at the doorway opening. Using the 'Trigger' collision preset ensures the character and other game objects can freely move through the simplified geometry.
The StaticMesh_Simple Component has an AkRoom component and an AkLateReverb Component attached. This way, the simple collision of the Building_Simple mesh is used for room containment tests.
To allow for sounds to reflect and diffract on the BuildingBP's mesh, an AkGeometry Component needs to be added to one of the Static Mesh Components. In this solution, because we are also using Reverb Parameter Estimation, it is best to add it to the StaticMesh_Simple component. The AkLateReverb Component uses the Acoustic Textures of its sibling AkGeometry Component to calculate HF Damping. Setting the AkGeometry Component to Static Mesh sends the full complex geometry to Wwise Spatial Audio instead of its simple collision mesh.
Finally, a Box Collision Component with an AkPortal Component attached is used to add an acoustic portal to the doorway.
A Point Light is also added to make the interior of the building visible.
Note:
|
Questions? Problems? Need more info? Contact us, and we can help!
Visit our Support pageRegister your project and we'll help you get started with no strings attached!
Get started with Wwise