Custom Sounds - Valheim-Modding/Wiki GitHub Wiki

Custom Sounds

This is a short introduction of custom sound, you should be familiar with Custom Item and Recipe Creation.

Making a new sound effect object

To create a new sound effect you can make a new prefab for your asset bundle. It is common practice to name it sfx_youreffectname. It should contain the following scripts:

  • TimedDestruction from assembly_valheim
  • ZNetView from assembly_valheim
  • ZSFX from assembly_valheim
  • Audio Source from Unity

add your custom the audio file to Audio Clips at the ZSFX component.

Fixing volume slider

If you add custom sound affects objects, the Audio Mixer Group of the AudioSource is not set and they are not impacted by the effects volume slider. Because the Audio Mixer Group is not decompiled properly, you cannot assign it directly.

But you can add the following script to any sound object:

public class AudioBinder : MonoBehaviour {
    private void Awake() {
        GetComponent<AudioSource>().outputAudioMixerGroup = AudioMan.instance.m_ambientMixer;
    }
}

It should now look like this:

audobinder

Playing sounds

Existing Events

You can assign your prefab to any existing EffectList, for example to a Piece.PlaceEffect list.

Custom play

The easiest way to play a sound is to use an EffectList object. Create the following line in a MonoBehaviour script and assign the value in the inspector.

public EffectList effects = new EffectList();

now you can play (all effects) at any given time with effects.Create(transform.position, Quaternion.identity);