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

Mapping Input Parameters to Grain Density

You will create logic to modulate grain density and duration based on gameplay variables like player velocity or intensity.

In this lesson, you will learn how to bridge the gap between player state and procedural synthesis by mapping dynamic gameplay variables directly to your MetaSound grain engine parameters.

The Logic of Granular Density

In a granular synthesizer, the "Grain Density" represents how many audio grains are triggered per second. When static, this can feel robotic; however, by mapping it to player intensity—such as velocity—you create a reactive audio environment where movement feels musically linked to sound.

To achieve this, we utilize the Input Parameter nodes in your MetaSound graph (e.g., a Float input named DensityMultiplier). We want to take a gameplay variable, like GetVelocity, normalize it to a 0.0 to 1.0 range, and pass it to the MetaSound instance via your AudioComponent.

Implementation Strategy

Inside your MetaSound graph, avoid connecting raw gameplay values directly to the grain duration or density. Instead, use a Map Range Clamped node to ensure that your input stays within the safe bounds of your granular engine.

// Within your Blueprint Logic (Actor or UI Widget)
float NormalizedSpeed = FMath::Clamp(CurrentVelocity / MaxVelocity, 0.0f, 1.0f);
AudioComponent->SetScalarParameter("DensityMultiplier", NormalizedSpeed);

Within the MetaSound graph:

  1. Input: Receive DensityMultiplier.
  2. Modulation: Route this into a Lerp node.
  3. Mapping: Connect the Lerp to the Spawn Rate of your granular player.
  4. Inverse Duration: A pro tip is to use a 1 / x operation on your density input to simultaneously decrease grain duration as density increases. This prevents "sonic sludge" and ensures that as the sound gets thicker, the individual grains remain crisp and distinct.

By utilizing the SetScalarParameter function, you decouple your UI/Gameplay logic from the low-level synthesis math, allowing the audio to respond fluidly to the player's actions in real-time. This provides the player with immediate, tangible feedback that their motion is physically carving the soundscape.

Key Takeaway: Map your gameplay variables to granular parameters using normalized ranges and inverse ratios to ensure that higher density sound remains articulate rather than cluttered.