From 8dc2345ceb73b4c8309caace222f5256be9f3ab8 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Sun, 29 Oct 2023 15:30:59 +1100 Subject: [PATCH] Fix audio position on first tick (#4533) --- Robust.Client/Audio/AudioSystem.cs | 10 +++++----- Robust.Shared/Audio/Components/AudioComponent.cs | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Robust.Client/Audio/AudioSystem.cs b/Robust.Client/Audio/AudioSystem.cs index 77903ff3c9d..b0fabaf9e1c 100644 --- a/Robust.Client/Audio/AudioSystem.cs +++ b/Robust.Client/Audio/AudioSystem.cs @@ -161,11 +161,6 @@ private void OnAudioStartup(EntityUid uid, AudioComponent component, ComponentSt // Don't play until first frame so occlusion etc. are correct. component.Gain = 0f; - if (!MetaData(uid).EntityPaused) - { - component.StartPlaying(); - } - // If audio came into range then start playback at the correct position. var offset = (Timing.CurTime - component.AudioStart).TotalSeconds % GetAudioLength(component.FileName).TotalSeconds; @@ -227,6 +222,11 @@ private void ProcessStream(EntityUid entity, AudioComponent component, Transform // TODO: // I Originally tried to be fancier here but it caused audio issues so just trying // to replicate the old behaviour for now. + if (!component.Started) + { + component.Started = true; + component.StartPlaying(); + } // If it's global but on another map (that isn't nullspace) then stop playing it. if (component.Global) diff --git a/Robust.Shared/Audio/Components/AudioComponent.cs b/Robust.Shared/Audio/Components/AudioComponent.cs index b38cac6150f..76bb5b28f8c 100644 --- a/Robust.Shared/Audio/Components/AudioComponent.cs +++ b/Robust.Shared/Audio/Components/AudioComponent.cs @@ -49,6 +49,10 @@ public sealed partial class AudioComponent : Component, IAudioSource #endregion + // We can't just start playing on audio creation as we don't have the correct position yet. + // As such we'll wait for FrameUpdate before we start playing to avoid the position being cooked. + public bool Started = false; + [AutoNetworkedField] [DataField(required: true)] public string FileName = string.Empty;