Overview
The Audio API provides high-level audio playback capabilities for game objects. It integrates with the Finewave audio engine to provide 3D spatial audio with support for effects, positioning, and listener-based attenuation.Finewave is required for audio components to work.
AudioPlayer Component
Component that provides audio playback capabilities to any object in the scene. It allows playing, pausing, and stopping audio with 3D spatial positioning.Constructor
Creates a new empty AudioPlayer object.
Lifecycle Methods
Initialize the audio player and prepare it for playback. Must be called before using the player.
Playback Control
Play the audio from the beginning or resume if paused.
Pause the audio playback. Can be resumed later with
play().Stop the audio playback and reset to the beginning.
Audio Source Configuration
Set the source from where the audio will be played.Parameters:
sourceResource(Resource): Resource containing the audio file
Spatial Audio
Set the position of the audio source in 3D space.Parameters:
position(Position3d): New position of the audio source
Enable spatialization for the audio source, making it 3D and affected by the listener’s position.
Disable spatialization for the audio source, making it play uniformly regardless of the listener’s position.
Properties
The underlying audio source. Allows for advanced manipulation of audio playback.
Example Usage
Attaching to GameObject
Background Music
Integration with Camera
The AudioPlayer automatically updates the audio listener position based on the main camera:Advanced Usage
Access the underlyingAudioSource for more control:
Notes
The AudioPlayer component calls
update() every frame to synchronize the listener position with the camera and update the audio source position with its parent GameObject.For best performance with many audio sources, use spatialization only for sounds that need 3D positioning. Background music and UI sounds should disable spatialization.