Fixed in 0.91 Preview 629

#422 [0.91 Preview 485] Music seems to randomly reset to a few seconds ago

area: sound
GameBugby @Ecconia1 year ago

I do not know why or when - but it happened.

The current song skipped back a few milliseconds and replayed a section constantly.

Some factors however do stop this, like MAYBE switching current GUI or end of track.

RSS icon
@JimmyDeveloper11 months ago

Disregard my previous comment – there was some confusion about which music-randomly-resetting bug we were talking about. The one I described in my previous comment was about stutters of a few milliseconds, and is now being tracked at

This issue report was about the music resetting to several whole seconds ago. I have properly fixed it for the next preview :)

@JimmyDeveloper11 months ago

Good grief, this was a hard bug to track down. Especially since you can never prove the absence of occasional random audio stutters in a build, only their direct presence. It took me FOREVER.

Here’s what’s happening:

  • Logic World uses Unity’s OnAudioFilterRead to synthesize the music notes for the music components (Singers and Drums).
  • AS IT TURNS OUT, using OnAudioFilterRead causes the audio thread to become subject to the managed garbage collector, even if you’re not making any allocations with it. This means that when garbage is collected, the audio thread is paused – this is the cause of the stuttering sounds you were hearing. Of course, this critical information is ABSOLUTELY NOWHERE IN THE DOCUMENTATION, and I only learned about it because I stumbled on this forum thread where a Unity dev explains this behavior.
  • So, this issue is actually present in 0.90 as well, but it only shows up after you place down a music component. I assume nobody reported this bug before now because if you’re messing with music components, you probably aren’t listening to the in-game music much (in fact, by default, playing a music component stops any in-game music that is playing)
  • In 0.91 there were many changes to how Logic World renders thumbnails, the little images that show a preview of the components in the Hotbar and Selection Menu. As part of these changes, the component scripts get initialized a bit more than they did in 0.90. This was causing OnAudioFilterRead to be run every time when the game starts up, as part of the process of rendering the thumbnails, so the audio glitches were always present instead of only when you were using music components like in 0.90.

I’ve tweaked the music component code to make sure OnAudioFilterReadonly gets called when it actually needs to be called, so the thumbnail rendering doesn’t trigger that method (thus dooming the audio thread) anymore. This reverts the status of this issue to the much better 0.90 behavior (actually slightly better – in 0.90, the audio thread gets doomed if a music component is placed in the world; in 0.91, you actually need to play a sound with a music component).

Unfortunately I don’t think a full solution is possible for now. I don’t think there’s a way to synthesize sounds with the built-in Unity audio system besides OnAudioFilterRead, and even the shortest pauses due to GC are liable to cause distortion in the playing music. I’m not 100% sure about that, it’s possible that expanding the audio buffer size and eliminating the most egregious allocations in the code would totally eliminate these issues, but I’ve already spent 30 goddamn hours on this and I’m moving on for now.

Later in Early Access, I was already planning to replace the built-in Unity audio system with a third-party solution to enable some epic upcoming features. This third-party system does not have the terrible awful no-good very bad audio thread pausing problems that Unity’s system does, so when we eventually make that upgrade, this issue will be fixed for good.

@Ecconia11 months ago

Oh noes, thanks for this explanation

@Kat1 year ago

I’ve also experienced this. The only fix I’ve found for my case has been setting the frequency to Never, then changing it back.

@Kat1 year ago

This actually happens extremely often for me, so I’ve resorted to just turning the music off for the time being.

@Ecconia1 year ago

Difficult to reproduce, I wonder if I will experience this again…