DEV505 / SOUND LAB / 05
A little rain.
Blend a storm, then hear thunder from its strike.
Try it in Unity
Section titled “Try it in Unity”In Unity’s Project window, open Assets/DEV505/SoundManager/Samples/05-Weather/Demo.unity. The supplied scene already has its Sound Manager, event registrations, generated keys, camera, and Audio Listener. Press Play, wait for the demo to be ready, and click the Game view before using the keyboard. If you are setting up a separate scene, follow Your first sound first.
| Control | Action |
|---|---|
| Space | Start or clear the weather. |
| 1 | Choose light rain. |
| 2 | Choose a storm. |
| T / thunder button | Request a strike when available. |
| Rain and wind sliders | Set the two weather targets. |
Start with light rain, then choose Storm. Listen as the rain fills out and wind strengthens over time. Trigger thunder: the lightning flash comes first, then the rumble. Clear the weather immediately after another strike to cancel a thunder request still waiting in its delay.
Rain and wind use a 2D event, providing a broad background. Thunder uses a 3D event at the strike point. The listener stays in the scene’s central listening area, so different strike positions change where the rumble is heard.
Two events with different jobs
Section titled “Two events with different jobs”Sounds.Weather supplies the continuous weather bed. Sounds.Thunder supplies a single delayed response. Both use the weather controller’s owner token, allowing one StopOwned call to clean up the whole interaction.
The Weather graph starts looping layers and maps Rain and Wind into their levels. Rain moves toward its target at 0.35 units per second upward and 0.5 downward; Wind uses 0.25 and 0.4. The demo starts both at zero in the initial context, then sets the requested targets, so the storm grows in instead of starting at full level.
The controller reads the current smoothed values to drive the rain and cloud visuals. The sound graph does not render those effects.
Thunder’s On Start reaches a 0.55-second Delay, then plays a randomly selected thunder variation. Playback speed varies slightly, from 0.92 to 1.06. After the recording finishes, the graph ends. This is a fixed artistic delay, not a calculation of the physical speed of sound from distance.
Start, strike, and clear
Section titled “Start, strike, and clear”var owner = service.OwnerOf(this);var context = SoundPlayContext.At(transform.position, owner) .With(SoundParameters.Weather.Rain, 0f) .With(SoundParameters.Weather.Wind, 0f);var result = SoundBus.Play(Sounds.Weather, context);Retain the accepted handle, then send Rain and Wind targets with SetFloat. For each lightning strike, use the actual strike position:
var strike = SoundBus.Play(Sounds.Thunder, SoundPlayContext.At(strikePosition, owner));// Show the flash only if strike.Accepted.// Later, when the player clears the weather:service.StopOwned(owner, 0.85f);The delay lives inside that thunder play. Stopping the owner cancels pending graph work as well as stopping weather voices; there is no separate delayed C# call left to fire afterward. The complete recipe keeps the owner until disable cleanup and releases it there.
The graph enforces a 4-second thunder cooldown. The demo’s button waits 4.2 seconds and automatic strikes use a longer interval. In a strong storm (Rain above 0.78 and Wind above 0.65), the demo schedules automatic strikes: first after about 6 seconds, then at random intervals of 8–12 seconds. That scheduling belongs to the controller.
What belongs to the demo?
Section titled “What belongs to the demo?”The cloud and island models, falling rain, flash light, lightning bolt, weather presets, and automatic strike schedule are demo features. Sound Manager supplies the looping layers, smoothing, random variations, delayed playback, spatial position, cooldown, and owner cleanup.
Common surprises
Section titled “Common surprises”- The rumble is not immediate. The graph deliberately waits after the visual flash.
- Repeated strikes are refused. Respect the cooldown rather than retrying each frame.
- Thunder happens after weather is cleared. Use the same owner for both events and stop that owner; stopping only the Weather handle leaves independent Thunder plays alive.
- The sliders change before the sound settles. They display targets; the graph smooths its current values.
Event settings, parameters, and signals
Section titled “Event settings, parameters, and signals”These are the saved graph settings. A play can supply different initial parameter values. Float smoothing is measured in units per second; a rate of 0 applies changes immediately.
Sounds.Thunder
- Position
- 3D · 4–20 units (minimum–maximum distance)
- Overlapping plays
- 2 ·
ReplaceOldest - Cooldown
- 4 seconds between accepted requests
- Owner loss
- Stop
- Keep Alive
- Off — ends when its work is finished
No exposed parameters.
Signals: None authored.
Sounds.Weather
- Position
- 2D
- Overlapping plays
- 1 ·
ReplaceOldest - Cooldown
- None
- Owner loss
- Stop
- Keep Alive
- Off — ends when its work is finished
| Parameter | Type | Default | Range | Rise / fall rate |
|---|---|---|---|---|
Rain | Float | 0 | 0–1 | 0.35 / 0.5 |
Wind | Float | 0 | 0–1 | 0.25 / 0.4 |
Signals: None authored.
For the meaning of these settings, see Playback settings. The default numbers above come from the Unity graph audit stored with this documentation.
Take it into your own game
Section titled “Take it into your own game”Open the complete integration recipe for the script, Inspector setup, a short test, and cleanup. Use Play context for initial values and placement, and SoundBus for playback controls.
All Weather Unity captures includes further states and readable graph details, with steps to reproduce each view.