Course contentsShow
← Unreal Engine Game Development
Lesson 615 of 8808. User Interface and MetaSoundsFree lesson

Exposing C++ Variables to MetaSound Graphs

Learn to define and register custom float or integer parameters in C++ to dynamically drive MetaSound graph inputs during runtime.

In this lesson, you will learn how to bridge the gap between your game’s C++ logic and MetaSound synthesis by dynamically updating input parameters at runtime.

The Bridge Between Code and Audio

MetaSounds are powerful because they are graph-based, but they are most effective when they respond to your C++ gameplay variables (like player health, speed, or environmental density). To influence a MetaSound from C++, you don't manipulate the graph directly; instead, you manipulate the UAudioComponent that is playing the MetaSound.

Because a MetaSound treats its inputs as data points, you use the SetFloatParameter or SetIntParameter functions on your UAudioComponent to push your C++ variables into the graph.

Practical Implementation

To pass a C++ variable, such as a float EngineRPM, to a MetaSound, ensure the MetaSound graph has an Input node with a matching name. In your C++ class, you typically perform this update within your Tick function or an event callback:

// Assuming MyAudioComponent is a UAudioComponent* referencing your MetaSound
void AMyVehicle::UpdateEngineSound(float NewRPM)
{
    // Ensure the name here matches the Input node in your MetaSound exactly
    MyAudioComponent->SetFloatParameter(FName("EngineRPM"), NewRPM);
}

Why This Matters

When you define an input in your MetaSound graph, it essentially becomes a variable waiting for a value. By using SetFloatParameter, you are dynamically injecting that value into the graph's execution flow.

It is important to remember that this operation is light, but it should be used judiciously. If you are updating dozens of parameters every single frame, ensure you are only pushing updates when the values actually change to keep your CPU overhead low. This approach decouples your gameplay logic from your sound design—your programmers define the "knobs" (the inputs), and your sound designers build the complex synthesis logic that reacts to those knobs.

Key Takeaway: You expose C++ variables to MetaSounds by mapping them to named Input nodes on a UAudioComponent using SetFloatParameter or SetIntParameter, allowing your game logic to drive synthesis parameters in real-time.