Game Audio

Unity Sound Variations Without Repeats: Randomize Creature Voices

A C# script that picks a different take every time, adds subtle pitch and volume changes, and keeps rapid events from spamming the same growl.

By ScreamBeast Team 11 min read

Unity Sound Variations Without Repeats: Randomize Creature Voices

A creature that plays the exact same growl every time it attacks stops sounding alive after the third swing. The fix is not more volume or a bigger reverb. It is variation: several takes of the same action, picked so the player never hears an obvious repeat, with small pitch and volume changes on top.

This guide shows you how to set up Unity random sound variation for creature voices with a short, readable C# script. You will build a CreatureVoice component that holds an array of clips per action, picks a different clip than the last one, adds subtle pitch and volume randomization, and uses a cooldown so rapid events don’t pile up into noise. You will also see a shuffle-bag alternative and where Unity 6’s Audio Random Container fits. The working example is a monster with six recorded variations per action.

Why does one creature sound repetitive even with good audio?

Players learn patterns fast. In combat, the same action can fire many times a minute: an attack, a hit reaction, a footstep effort. If each event triggers the same file, the ear catches the repeat almost immediately, and the creature starts to sound like a machine playing a sample rather than a body reacting to what is happening.

Three things usually cause it:

  • One clip per action. Even an excellent roar becomes a stamp when it is the only option.
  • Pure random selection. Picking any clip at random still allows the same clip twice in a row. With six clips, that happens on roughly one call in six.
  • Overlapping triggers. Several hit events in the same moment can stack identical voices into a loud, phasey burst.

The approach below addresses each one: multiple recorded takes, a picker that never repeats the previous clip, and a per-action cooldown.

How many variations do you need per action?

There is no universal number, but the frequency of the action is a useful guide. Actions that fire constantly, such as hits, attacks and locomotion efforts, benefit most from several takes. Rare, one-time actions, such as a death cry, need fewer, though a couple of options still help when many enemies die in the same level.

Six variations per action is a comfortable working set for a game creature. It is enough that a no-repeat picker produces sequences the player can’t easily predict, and small enough that you can still audition and balance every take by ear. That is the structure of the packs used as the example here: each action ships as six separately recorded performances, not one file pitched six ways.

Real takes matter. Pitch randomization on a single clip helps a little, but the attack, length and texture stay identical, so the repeat is still audible. Different performances change the shape of the sound, and light pitch and volume randomization on top of those takes hides what remains.

If you are still deciding which actions your enemy needs in the first place, start with building one enemy’s complete vocal set, then come back to wire up the variations.

What do six takes of one action look like in a project?

Import the WAV files and keep each action’s takes together. A clear naming pattern makes the Inspector setup quick. ScreamBeast files follow a pattern like SB_Monster_Attack_01.wav through SB_Monster_Attack_06.wav, so you can select all six attack takes and drag them into an array in one move.

For short creature vocals, a few import settings are worth checking in the AudioClip Inspector:

  • Load Type: Decompress On Load is a common choice for short, frequently triggered clips. Longer ambient beds are often better as Compressed In Memory or Streaming.
  • Force To Mono: consider it for voices that will be played from a 3D AudioSource, since spatialization positions a mono source anyway.
  • Normalization of takes: listen to all six side by side. If one take is noticeably louder, trim its level in your editor or adjust it per clip rather than letting the random volume range hide the difference.

Listen to the actions you will randomize

These previews come from Monster Sound Effects Pack — Volume 1, which has 14 actions with six variations each (84 WAV files). Each player below is one take of an action; in the pack, every one of these actions has six takes you would drop into the same AudioClip[] array.

Monster demo reel

Attack

Abdomen hit

Threatening

Walk

Death

These previews include a light musical watermark. The WAV files you buy are clean.

How do you pick a random clip without repeating the last one?

The simplest reliable method: remember the index you played last, then choose from every other index. Instead of rerolling in a loop until you get something different, pick from count - 1 slots and skip over the previous index. It always finishes in one step and stays evenly distributed across the remaining clips.

Here is the full component. Add it to your creature, alongside an AudioSource:

using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(AudioSource))]
public class CreatureVoice : MonoBehaviour
{
    [System.Serializable]
    public class VoiceAction
    {
        public string actionName = "Attack";
        public AudioClip[] clips;

        [Range(0f, 1f)] public float minVolume = 0.85f;
        [Range(0f, 1f)] public float maxVolume = 1f;
        [Range(0.5f, 1.5f)] public float minPitch = 0.96f;
        [Range(0.5f, 1.5f)] public float maxPitch = 1.04f;
        [Min(0f)] public float cooldown = 0.3f;

        [System.NonSerialized] public int lastIndex = -1;
        [System.NonSerialized] public float nextAllowedTime;
    }

    [SerializeField] private VoiceAction[] actions;

    private AudioSource source;
    private readonly Dictionary<string, VoiceAction> lookup =
        new Dictionary<string, VoiceAction>();

    private void Awake()
    {
        source = GetComponent<AudioSource>();
        source.playOnAwake = false;

        foreach (VoiceAction action in actions)
        {
            lookup[action.actionName] = action;
        }
    }

    // Call this from gameplay code, e.g. voice.Play("Attack");
    public void Play(string actionName)
    {
        if (!lookup.TryGetValue(actionName, out VoiceAction action)) return;
        if (action.clips == null || action.clips.Length == 0) return;
        if (Time.time < action.nextAllowedTime) return;

        int index = PickIndex(action);
        action.lastIndex = index;
        action.nextAllowedTime = Time.time + action.cooldown;

        source.pitch = Random.Range(action.minPitch, action.maxPitch);
        float volume = Random.Range(action.minVolume, action.maxVolume);
        source.PlayOneShot(action.clips[index], volume);
    }

    private static int PickIndex(VoiceAction action)
    {
        int count = action.clips.Length;
        if (count == 1 || action.lastIndex < 0)
        {
            return Random.Range(0, count);
        }

        // Pick from every index except the last one, then skip over it.
        int index = Random.Range(0, count - 1);
        if (index >= action.lastIndex) index++;
        return index;
    }
}

A few details are worth understanding before you use it:

  • Random.Range with integers excludes the maximum. Random.Range(0, count - 1) returns 0 to count - 2, which is exactly the number of “other” clips. Incrementing when the result reaches lastIndex skips the previous clip.
  • PlayOneShot lets takes overlap naturally. A new attack can start while the tail of the previous one is still ringing, which sounds more organic than cutting it off with Play().
  • Pitch is set on the source. AudioSource.pitch also affects one-shots that are still playing on that source, so a new pitch value can slightly bend a tail that is still ringing. Keep the range narrow, or give long or frequent actions their own AudioSource if you hear it.
  • Time.time follows Time.timeScale. If your pause menu sets the time scale to zero, cooldowns pause too, which is usually what you want for in-world voices.

What pitch and volume ranges sound natural for creature voices?

Start small. The defaults in the script, pitch between 0.96 and 1.04 and volume between 0.85 and 1.0, are a conservative starting point, not a rule. Pitch on an AudioSource is a playback-speed multiplier, so it changes length and timbre together. Push it too far and a large monster starts to sound like a smaller or larger animal, which breaks the character you chose the voice for.

Tune by ear, per action:

  • Hits and hurt reactions can usually take a bit more pitch variation, because they fire often and are short.
  • Attacks and threats carry the creature’s identity. Keep them closer to the original.
  • Death rarely needs pitch randomization at all; the six takes already supply variety.

Test in context with music and other effects playing. A variation range that sounds obvious in isolation often disappears in a busy mix.

Should you use a shuffle bag instead?

The no-repeat picker prevents back-to-back repeats, but over a long fight the same clip can still come up more often than the others for a while. A shuffle bag fixes that: it plays every clip once, in a random order, before any clip plays again.

using System.Collections.Generic;
using UnityEngine;

public class ShuffleBag
{
    private readonly List<int> order = new List<int>();
    private readonly int count;
    private int position;
    private int last = -1;

    public ShuffleBag(int count)
    {
        this.count = Mathf.Max(1, count);
    }

    public int Next()
    {
        if (position >= order.Count) Refill();
        last = order[position++];
        return last;
    }

    private void Refill()
    {
        order.Clear();
        for (int i = 0; i < count; i++) order.Add(i);

        // Fisher-Yates shuffle
        for (int i = count - 1; i > 0; i--)
        {
            int j = Random.Range(0, i + 1);
            (order[i], order[j]) = (order[j], order[i]);
        }

        // Don't let a new cycle start with the clip that ended the previous one.
        if (count > 1 && order[0] == last)
        {
            (order[0], order[count - 1]) = (order[count - 1], order[0]);
        }

        position = 0;
    }
}

To use it in CreatureVoice, give each action a bag and ask it for the next index:

// In VoiceAction:
[System.NonSerialized] public ShuffleBag bag;

// In Awake(), inside the foreach:
action.bag = new ShuffleBag(action.clips.Length);

// In Play(), instead of PickIndex(action):
int index = action.bag.Next();

Which one to pick depends on the action. A shuffle bag gives the most even coverage, which suits constant sounds like hits and efforts. The no-repeat picker is less predictable across cycles, which can suit rarer calls such as threats. Both are fine for a six-take set; the important part is that the same file never plays twice in a row.

How do you stop rapid events from spamming the same voice?

The cooldown in Play() handles it. When an action fires, the script stores the earliest time that action may play again. Any call before that is ignored. Without it, a shotgun blast that registers several hits in one frame can trigger several overlapping hurt voices at once.

Set the cooldown per action:

  • Hit reactions: long enough that bursts of damage produce one clear reaction, not a chorus.
  • Attacks: roughly matching the attack animation, so the voice can’t restart halfway through.
  • Death: a large value, since it should play once.

If several creatures of the same type share a scene, you may also want a shared limit so a group doesn’t trigger the same call at once. Unity’s AudioSource.priority and the project’s Max Real Voices setting control what gets culled when many sounds play, but they won’t stop a wall of identical growls, so a simple shared cooldown in your own code is often the clearer fix.

How do you trigger the voice from gameplay?

Call Play with the action name you typed in the Inspector, from whatever code already knows the state changed:

public class MonsterAI : MonoBehaviour
{
    [SerializeField] private CreatureVoice voice;

    public void OnAttackStarted() => voice.Play("Attack");
    public void OnDamaged()       => voice.Play("Abdomen Hit");
    public void OnDied()          => voice.Play("Death");
}

Because Play is a public method with a single string parameter, you can also call it from an Animation Event on the attack or death clip, which lines the voice up with a specific frame. That workflow deserves its own walkthrough, so we only mention it here.

If you are on a tight schedule, the same script works well in a jam project: drop it on the creature, fill the arrays, and wire three calls. The game jam sound effects guide covers how to scope audio when time is short.

What about the Audio Random Container in Unity 6?

Unity 6 includes an Audio Random Container asset that handles playlist randomization without code. You create it from the Project window (Create > Audio > Audio Random Container), add your clips, and assign it to an AudioSource in place of a single clip. According to Unity’s documentation, it offers Sequential, Shuffle and Random playback modes, an Avoid Repeating Last setting, and volume and pitch randomization ranges. In Manual trigger mode, each call to AudioSource.Play() advances the playlist.

It is a good option when you want designers to tune variations in the Editor. Keep two points in mind:

  • PlayOneShot takes an AudioClip, so it doesn’t play a container. You trigger the container with Play() on the source that references it, which means one container per source.
  • A creature with many actions would need several containers and sources. The script above keeps every action on one component, which some teams find easier to manage.

Neither approach is wrong. Check the documentation for your exact Unity version, since audio features change between releases.

Frequently asked questions

Does Unity random sound variation work with 3D audio?

Yes. PlayOneShot uses the source’s spatial settings, so set the AudioSource Spatial Blend toward 3D and the variations will be positioned on the creature like any other sound.

Is pitch randomization alone enough?

It helps, but a single clip at different pitches keeps the same attack, rhythm and texture. Several recorded takes, with light pitch and volume changes on top, are much harder to spot.

Can I use this script with the zombie or alien packs?

Yes. The script doesn’t care which creature it voices. Fill each action’s array with that pack’s takes and rename the actions to match.

Why not just pick a random clip each time?

Pure random selection allows the same clip twice in a row. With six clips, that happens on about one call in six, often enough for players to notice in a long fight.

Do the purchased files include the watermark?

No. Only the website previews carry a light musical watermark. The WAV files in the pack are clean.

ScreamBeast

Need creature sounds for your project?

Royalty-free creature sound effects packs, or your own voice turned into a monster in the Voice Studio.

Related articles