Table of Contents

Class SoundEmitterScript

Namespace
Stride.CommunityToolkit.Audio
Assembly
Stride.CommunityToolkit.dll

Positions a spatialised SoundInstance at its entity every frame, so the sound is heard from where the entity is.

[DataContract("SoundEmitterScript")]
[Display("Sound Emitter (runtime instance)", null)]
[ComponentCategory("Audio")]
public class SoundEmitterScript : SyncScript, IIdentifiable, ICollectorHolder
Inheritance
SoundEmitterScript
Implements
Inherited Members
Extension Methods

Examples

var listener = game.GetAudioSystem().AttachListener(game.GetCameraEntity());
var instance = chime.CreateInstance(spatialized: true, listener: listener);

entity.Add(new SoundEmitterScript { Instance = instance });
instance.Play();

Remarks

The engine's AudioEmitterComponent does this for asset-based Sounds only. A runtime instance - from CreateProceduralSound(AudioSystem, SampleFiller, int, bool, bool, bool, AudioListener?) or CreateInstance(bool, bool, AudioListener?) with spatialized: true - is positioned by calling Apply3D(AudioEmitter) with an AudioEmitter, and this script does that with the entity's world transform: position, forward and up from the matrix, velocity as the position change since the previous frame. That last one matches how the engine's listener processor estimates velocity, so Doppler sees both sides the same way.

Spatialisation is relative to the listener the instance was created with. By default that is the engine's default listener, which never moves; pass the result of AttachListener(AudioSystem, Entity) when creating the instance for a listener that follows the camera.

Properties

Emitter

The emitter handed to Apply3D(AudioEmitter), for reading back or for adjusting between frames.

[DataMemberIgnore]
public AudioEmitter Emitter { get; }

Property Value

AudioEmitter

Instance

The instance to position. Must have been created with spatialized: true; swapping it at runtime is fine.

[DataMemberIgnore]
public SoundInstance? Instance { get; set; }

Property Value

SoundInstance

Methods

Update()

public override void Update()