Sound effect variations for Godot and Unity
By flreey · Published
Play the same footstep, sword swing or hit a hundred times and players hear it: the “machine-gun” effect. Games avoid it with a few close versions of each sound, played at random, never the same one twice in a row, with a little pitch on top. This page shows how to make those versions with AI and play them in Godot 4 and Unity.
1. Make the variations
In AI Studio, describe one sound and listen to the 4 takes. Keep the one that fits and ask for Variations: 4 new takes made from that take's own audio. They keep its material, size and room and change only the details, the way two real steps on the same floor differ. Describe a single event (“one footstep”, not “walking”) so each file is one trigger in your game.
4 variations of one monster footstep, made in AI Studio. Each press plays another one:
Start from one of these, or write your own:
Making and hearing takes is free. The Variations download is one ZIP: the WAVs, a Godot resource, a Unity script and a README. It needs a credit or a plan (from $3.90 for 10 credits), and makes the sounds CC0 for commercial games.
2. Play them at random in Godot 4
Godot 4 has a resource for this: AudioStreamRandomizer. In Random (Avoid Repeats) mode it never plays the same stream twice in a row, and its random pitch adds up to 5% either way. The ZIP's .tres is set up like this:
[gd_resource type="AudioStreamRandomizer" load_steps=5 format=3]
[ext_resource type="AudioStream" path="res://sfx/sfxmint-footstep-wood-1.wav" id="1"]
[ext_resource type="AudioStream" path="res://sfx/sfxmint-footstep-wood-2.wav" id="2"]
[ext_resource type="AudioStream" path="res://sfx/sfxmint-footstep-wood-3.wav" id="3"]
[ext_resource type="AudioStream" path="res://sfx/sfxmint-footstep-wood-4.wav" id="4"]
[resource]
playback_mode = 0
random_pitch = 1.05
streams_count = 4
stream_0/stream = ExtResource("1")
stream_0/weight = 1.0
stream_1/stream = ExtResource("2")
stream_1/weight = 1.0
stream_2/stream = ExtResource("3")
stream_2/weight = 1.0
stream_3/stream = ExtResource("4")
stream_3/weight = 1.0
Put the WAVs and the .tres in res://sfx/, set an AudioStreamPlayer's Stream to the .tres (or build the same resource in the Inspector: New AudioStreamRandomizer, add the WAVs), and play it when the event happens:
@onready var steps: AudioStreamPlayer = $Footsteps
func _on_foot_down() -> void:
steps.play() # another variation each time, with a little pitchFor a 3D game use AudioStreamPlayer3D the same way. If steps can overlap (running), raise the player's max_polyphony to 2 or 3 so a new step does not cut the last one off.
3. Play them at random in Unity
The ZIP brings RandomSfx.cs: add it to a GameObject, drag the WAVs into Clips, and call Play(). It picks a clip at random, never the last one again, and sets a pitch within 5%.
using UnityEngine;
// Plays one of its clips at random, never the same one twice in a row, with a little pitch.
// Add it to a GameObject, drag the WAVs into Clips, and call Play() when it happens.
[RequireComponent(typeof(AudioSource))]
public class RandomSfx : MonoBehaviour
{
public AudioClip[] clips;
[Range(0f, 0.2f)] public float pitchSpread = 0.05f;
AudioSource source;
int last = -1;
void Awake() => source = GetComponent<AudioSource>();
public void Play()
{
if (clips == null || clips.Length == 0) return;
int i = Random.Range(0, clips.Length);
if (clips.Length > 1 && i == last) i = (i + Random.Range(1, clips.Length)) % clips.Length;
last = i;
source.pitch = 1f + Random.Range(-pitchSpread, pitchSpread);
source.PlayOneShot(clips[i]);
}
}
// From an animation event on the foot's down frame, or from your controller:
public RandomSfx footsteps;
void OnFootDown() => footsteps.Play();Unity 6 also has a built-in Audio Random Container asset that does the same from the Inspector. Either way works with the same files.
4. Import settings
- Use the WAVs for short cues. They start on the first sample; MP3 can add a few milliseconds of silence.
- Godot: keep the WAV import's loop mode off for one-shots. Name the files with numbers (
-1,-2…) so they sort together. - Unity: set short clips to Decompress On Load so they play without delay; leave longer ambience on Streaming.
- Levels: the variations of one sound come out at the same loudness, so one volume on the player fits all of them.
Without making anything: the free library
The free CC0 library has single footsteps on grass, wood, concrete, gravel and metal. Pick three or four on the same surface and play them with the same Godot resource or Unity script. They were made separately, so listen to them side by side: unlike Variations of one take, they can differ in size or room. The walking clips (wood, gravel, snow) hold several steps each: use them for cutscenes or a looped walk, not for one step per animation frame.
Questions
How many variations does a sound need?
Three or four are enough for most cues: with no repeats in a row and a little pitch, players stop hearing a pattern. Footsteps on a surface the player crosses a lot can take six to eight. AI Studio makes 4 at a time; ask again for more.
Will the variations sound like the same thing?
Yes. Variations are made from the take you keep, its own audio, not from the words again, so they keep its material, size and space and differ only in the details, like real steps or hits do.
Can I use them in a commercial game?
Yes, once a credit or a plan made them: they are CC0, with no credit needed. Making and hearing them is free; the download with the Godot and Unity files starts at $3.90 for 10 credits. On Steam or itch.io, disclose that the sounds are AI-generated.
Does this work in Godot 3?
AudioStreamRandomizer is Godot 4 only. In Godot 3, keep the WAVs in an array and pick one at random before each play, skipping the last one; the Unity script below shows the logic.