FMOD Properties in Unreal Engine 5 - C++ (Events, Instances, snapshots, and more…)
Si prefieres leer una versión en Español, da click en este botón =>
Unreal Engine Version: 5.0.3
FMOD Version: 2.02.07
This blog post is a simple guide about the essential FMOD Properties we need to create our audio systems in Unreal Engine 5. We will learn what they are, what they do, and how to define/declare them in C++ and then expose them to Blueprints.
IMPORTANT!
〰️
IMPORTANT! 〰️
Prerequisites:
Create an empty C++ third-person project called “MyUE5Project”.
Download and integrate FMOD’s plugin into your project.
Create a new FMOD Studio project and set your bank’s output directory to MyUEProject/Content/FMOD
Build your Master Bank
For this tutorial to make sense, you need to know how to integrate the FMOD plugin into Unreal Engine. Additionally, consider reading and referencing my previous post about UPROPERTY & UFUNCTION:
IMPORTANT!
〰️
IMPORTANT! 〰️
First Steps:
On the UE5 editor, go to Tools > Open Visual Studio or Tools > Open Xcode.
Open the Content Drawer and click on Settings, then select Show C++ Classes.
The C++ Classes folder will be exposed.
In the Content Drawer go to "MyUE5Project” folder. Right-click and select “New C++ Class”.
Create an Actor type class and name it “MyCPPActorClass.”
Inside your IDE go to Games/MyUEProject/Source/MyUEProject and open both “MyCPPActorClass.cpp” and "MyCPPActorClass.h”
About .h and .cpp files: Every time you create a class in Unreal Engine, you end up with two files. The .h file or "header" will hold your "Declarations" (Properties/Variables, Constants, and Functions), and the .cpp file will have the "Implementations" or "Definitions" of these declarations.
FMOD Properties:
Our properties will be declared on our "MyCPPActorClass.h". To simplify our testing, we will put all these properties under the public access specifier and write this UFUNCTION macro above all of them (Read the UPROPERTY & UFUNCTION post to learn more):
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Audio")
1. Event (UFMODEvent*)
An event is the most essential FMOD asset. An event will hold your sound effects and music cues and can be instantiated in your game.
From Firelight Technologies - FMOD:
An event is an instantiable unit of sound content that can be triggered, controlled, and stopped from game code. Everything that produces a sound in a game should have a corresponding event.
.h file:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Audio") UFMODEvent* myEvent;
Editor and Blueprints:
2. Event Instance (FFMODEventInstance)
When an FMOD Event is triggered by a function, some will create Event Instances, giving us more control over our sounds (Play, Pause, Stop, Set Parameters).
From Firelight Technologies - FMOD:
Your game can play multiple instances of each event in your project. It is even possible for multiple instances of the same event to be playing simultaneously.
All instances of the same event have the same content. However, each event instance has its own timeline position, position in 3D space, random modulator adjustments, playlist selections, and parameter values. Different instances of the same event can therefore produce very different output, even if they play simultaneously.
.h file:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Audio") FFMODEventInstance myEventInstance;
Editor and Blueprints:
3. Audio Component (UFMODAudioComponent*)
When an FMOD Event is triggered by a function, some will create Audio Components that will give us more control over our sounds (Play, Pause, Stop, Set Parameters). Additionally, Audio Components are attached to a position in the world, so it’s easy for the game engine to properly give spatialization, occlusion, and attenuation properties to these sounds.
.h file:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Audio") UFMODAudioComponent* myAudioComponent;
Editor and Blueprints:
4. Bank (UFMODBank*)
An FMOD bank will carry your audio events and load them into memory. You can assign your events to different banks. Additionally, you can load/unload them anytime to achieve the best optimization considering your game's design and architecture. By default, Unreal Engine loads all your banks at startup; this behavior can be disabled at Edit > Project Settings > Plugins > FMOD Studio > Basic > Load All Banks
From Firelight Technologies - FMOD:
A bank is a collection of events from your FMOD Studio project, formatted and compressed for use with the version of the FMOD Engine integrated into in your game. Banks allow you to choose which content is loaded into memory at any given time.
.h file:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Audio") UFMODBank* myBank;
Editor and Blueprints:
5. Bus (UFMODBus*)
An FMOD bus in a component from the audio mixer where you can assign, route, and sum your audio event's sounds. These buses behave the same as in any major DAW (Reaper, Nuendo, Pro Tools, Logic, etc.), but they can also be controlled by the game engine.
From Firelight Technologies - FMOD:
In FMOD Studio, a bus is a modular component of the mixer that produces a submix from the signals routed into it and has its own signal chain. All buses, other than port buses and the master bus, can be routed into group buses, into port buses, or into the master bus.
.h file:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Audio") UFMODBus* myBus;
Editor and Blueprints:
6. VCA (UFMODVCA*)
An FMOD VCA is a fader that allows us to control the volume of several Events, Busses, and Returns simultaneously. No audio is routed to them.
From Firelight Technologies - FMOD:
VCAs are a way of grouping buses for the purposes of volume control.
Events, group buses, and return buses can all be assigned to VCAs. Signals are not routed through VCAs but are assigned as parallel controls of the main signal chain.
VCAs can be useful for general project balancing and level mixing as they provide a quick way of grouping and adjusting events without affecting the signal chain in any way.
.h file:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Audio") UFMODVCA* myVca;
Editor and Blueprints:
7. Snapshot (UFMODSnapshot*)
An FMOD Snapshot is a group of changes that can be triggered and stopped just as FMOD Events, almost any parameter within your FMOD Studio project can be manipulated by a snapshot.
IMPORTANT: To access this property, you need to include this directive in your .h file:
#include “FMODSnapshot.h“
From Firelight Technologies - FMOD:
A snapshot is an instantiable unit of changes to the project mix that can be triggered, controlled, and stopped from game code in the same manner as an event. Each snapshot represents a different way your game's mix can change in response to the circumstances in your game as it runs.
.h file:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Audio") UFMODSnapshot* mySnapshot;
Expose Your Properties To The Editor and Blueprints:
After writing all these FMOD properties in your "MyCPPActorClass.h" file, your code should look similar to this:
Save your modified code. Go back to your UE project and compile.
Drag "MyCPPActorClass” inside your map on the outliner.
Create a Blueprint Class based on “MyCPPActorClass” called “MyBPActorClass.” Drag it inside your map on the outliner too.
Open your "MyBPActorClass" blueprint event graph. You should be able to see all your FMOD C++ properties on the bottom-left of your editor under Variables > Audio. If you can't see them, try clicking on the cog-shaped icon on the top-right of My Blueprint tab and then select Show Inherited Variables.