Fix spatial audio playback when clip is set after the audio source was enabled

#1622
This commit is contained in:
Wojtek Figat
2023-10-06 14:34:08 +02:00
parent 92e28f66af
commit a698095bdd
2 changed files with 9 additions and 0 deletions

View File

@@ -265,6 +265,7 @@ void AudioSource::Cleanup()
void AudioSource::OnClipChanged()
{
Stop();
_clipChanged = true;
}
void AudioSource::OnClipLoaded()
@@ -318,6 +319,12 @@ void AudioSource::SetNonStreamingBuffer()
void AudioSource::PlayInternal()
{
if (_clipChanged && SourceIDs.HasItems())
{
// If clip was changed between source setup (OnEnable) and actual playback start then ensure to flush any runtime properties with the audio backend
_clipChanged = false;
AudioBackend::Source::SpatialSetupChanged(this);
}
AudioBackend::Source::Play(this);
_isActuallyPlayingSth = true;
@@ -482,6 +489,7 @@ void AudioSource::OnEnable()
{
_prevPos = GetPosition();
_velocity = Vector3::Zero;
_clipChanged = false;
Audio::OnAddSource(this);
GetScene()->Ticking.Update.AddTick<AudioSource, &AudioSource::Update>(this);

View File

@@ -53,6 +53,7 @@ private:
bool _loop;
bool _playOnStart;
bool _allowSpatialization;
bool _clipChanged = false;
bool _isActuallyPlayingSth = false;
bool _needToUpdateStreamingBuffers = false;