Sound
FMOD is used for all sounds in the project.
Installation
Download the FMOD plugin from the Asset Store.
Add the FMOD scripting define to the project.
Select the project FMOD path in the window that appears on the Linking tab (by default DotsCity/FMOD/fmodproject/fmodproject.fspro).
Sign up & download the FMOD Studio software from the official site (official guide).
Open FMOD settings.
By default, project path: FMOD project path DotsCity/FMOD/fmodproject/fmodproject.fspro, make sure that the FMOD project path is set correctly.
How To Use
Open FMOD Studio installed on your computer.
Open Bank bookmark.
If you do not have an existing bank or need to create a new one, right-click in the window and press New Bank.
In the bookmark Events - Create or open exist folder.
Right-click on the created folder and press Create Event, rename created event.
Right-click on Add Timeline Sheet in the created event.
Drag and drop the desired sound into the timeline.
Customize your sound.
Assign the selected FMOD event to the Bank.
Build FMOD project.
Create Sound Data in the Unity project.
Enter trigger name event:/Vehicle/TestExample.
Note
Sound ID is created automatically.
Press Add To Service button to add sound to the FMOD sound service.
Now, we can trigger the sound from the code.
Sound Data
Contains data about the FMOD sound.
How To Create
Select from the project context menu:
Spirit604/City/Sound/Sound Data
![]()
Settings
FMOD Sound Service
Contains data on all sounds in the Unity project.
![]()
Warning
If you do not add sound to the service, it cannot be activated from the code.
Code Examples
Sound Types
Default : default sound entity.
One Shot : entity played once & destroyed afterwards.
Tracking : entity tracks target entity.
Tracking Vehicle : entity tracks target vehicle entity.
Tracking And Loop : entity tracks target entity & loop playback.
How To Create
EntityManager methods
SoundExtension.CreateSoundEntity(ref this EntityManager entityManager, int soundId, float volume = 1f)
// Creating a default sound entity.
SoundExtension.CreateTrackedSoundEntity(ref this EntityManager entityManager, int soundId, Entity parentEntity, float volume = 1f)
// Creation of a sound entity that follows a given entity.
SoundExtension.CreateChildSoundEntity(ref this EntityManager entityManager, int soundId, Entity parentEntity, float volume = 1f)
// Creation of a sound entity that will be a child of a given entity.
CommandBuffer methods
Burst compatible methods.
SoundExtension.CreateSoundEntity(ref this EntityCommandBuffer commandBuffer, Entity soundPrefabEntity, int soundId, float volume = 1f)
// Creating a default sound entity.
SoundExtension.CreateSoundEntity(ref this EntityCommandBuffer commandBuffer, Entity soundPrefabEntity, int soundId, float3 position, float volume = 1f)
// Create a sound entity at a specific position.
Create prefab query method
SoundExtension.GetSoundQuery(EntityManager entityManager, SoundType soundType)
// Get `EntityQuery` with the selected `Sound type`.
Params
soundId : id of sound taken from sound data.
soundPrefabEntity : sound prefab entity taken from EntityQuery.
position : initial position of the sound.
volume : volume of the sound (0..1 range).
How To Play
public partial class PlayAndStopSoundExampleSystem : SystemBase
{
protected override void OnUpdate()
{
// Get world sounds
var sounds = GetComponentLookup<FMODSound>(true);
Entities
.WithBurst()
.WithReadOnly(sounds)
.ForEach((
Entity entity
in SoundHolder soundHolder) =>
{
// Some play condition
bool shouldPlay = true;
// Some sound entity container component
Entity soundEntity = soundHolder.Entity
FMODSound fmodSound = sounds[soundEntity];
if (shouldPlay)
{
fmodSound.Event.start();
}
else
{
fmodSound.Event.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
}
}).Schedule();
}
}
How To Destroy
Add the PooledEventTag component to the sound entity.
How To Loop
Create a Sound entity.
Add a LoopSoundData component (assign a Duration value).