Skip to content

Adding a Vehicle Voice

Michael Neises edited this page Feb 18, 2024 · 5 revisions

This guide will teach you how to add a custom voice to your ModVehicles.

You will learn:

  • How VehicleFramework uses a "VehicleVoice"
  • How to format your audio clips
  • How to use VF to easily add your clips to the game

Vehicle Voice

There are 17 audio clips that the AutoPilot will sometimes play. You can see where that happens here

EnqueueClip

And all invocations of that method are found in AutoPilot.cs

Basically, the AutoPilot implements several interfaces: IVehicleStatusListener, IPlayerListener, IPowerListener, ILightsStatusListener, IAutoPilotListener

Each of which is a kind of event-trigger. The AutoPilot does not respond to every single event trigger, but it responds to many of them.

Audio Clips

Your audio clips must be formatted as .ogg files because of the limited methods for importing audio to the game at run-time. The .ogg filetype is the only one VehicleFramework supports.

Your audio clips must be named exactly the same as every other voice.

Your audio clips must be organized in a particular way to be easily picked up by Vehicle Framework. They should all be in a folder whose name is the voice name. That folder should then be in a folder called AutoPilotVoices in your mod folder. See the following pictures for an example.

Registering your Voice with Vehicle Framework

There are only two things to do:

  • Register the voice
  • Make sure your vehicle uses the voice

To register our voice, we'll invoke the appropriate method in the Start() of our BaseUnityPlugin. That way, we can be sure we only access the disk only once during the life of the mod AND be sure we grab the files before we need them. The string "Testjaw" here is exactly the name of the folder that holds our voice clips.

string modFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
UWE.CoroutineHost.StartCoroutine(VehicleFramework.VoiceManager.RegisterVoice("Testjaw", modFolder));

To configure our vehicle to use the voice, we'll take action in the Start() of our vehicle.

voice.voice = VehicleFramework.VoiceManager.GetVoice("Testjaw"); // make sure this string matches the registration
voice.blockVoiceChange = true; // only set this if you want your vehicle to exclusively use this voice