Ran into a rather unfortunate, but devastating problem that I’m hoping someone can shed some light on–tried asking on the main Unity forums, but it’s all crickets there. The main gist is as such: We have two main scenes and a loading scene. Whenever the player transitions to the next scene, we move them into a loading scene while the next scene asynchronously loads–pretty standard stuff, right?

In order to have music continue playing all the while, the AudioSource component is attached to our GameManager object, which is marked as DontDisableOnLoad (or whatever it’s called), thus it persists between all scenes. However, every 1 in 100 or so transitions, Unity inexplicably crashes–interestingly, the actual AudioSource’s clip is NEVER changed during this time–it always plays the same song on a loop. However, as we don’t use a persistent camera (the camera belongs to each loaded scene, including the loading screen itself), the AudioListener changes each time a transition is encountered. Also, the Audiosource’s clip is set to loop.

Even more interesting is that it never crashes on the LoadingScreen itself–it’s always one of the two ‘main game’ scenes that seems to crash before being fully loaded. As you can imagine, this is an incredibly frustrating bug that seems to have no obvious cause–I can confirm though, however, that it does not happen when the loading screen is not used. Let me repeat: when LoadLevelAsync is not called/used, there is never a crash. Frustratingly, it also never happens during Debug mode. I know this because I set up a test to force the player character to repeatedly move between the scenes. This runs over night and crashes, without fail, within 100 iterations or so, but when asynchronous scene loading isn’t used/Debug Mode is enabled, it’s still running in the morning, after some 20k iterations.

Again, I’d love to provide a repro project, but it’d be incredibly difficult at this point, given the maturity and complexity of our project. Mainly just posting this to see if anyone can throw out any leads. With debug symbols enabled, this is the stack trace I get when it crashes:

========== OUTPUTING STACK TRACE ==================

0x00007FFB7E729B71 (UnityPlayer) FMOD::Codec::read
0x00007FFB7E7226A3 (UnityPlayer) FMOD::CodecFSB5::readInternal
0x00007FFB7E729B71 (UnityPlayer) FMOD::Codec::read
0x00007FFB7E6DCCC5 (UnityPlayer) FMOD::SoundI::readData
0x00007FFB7E6DB6F1 (UnityPlayer) FMOD::SoundI::read
0x00007FFB7E6C80AE (UnityPlayer) FMOD::SystemI::createSoundInternal
0x00007FFB7E6C9301 (UnityPlayer) FMOD::SystemI::createSound
0x00007FFB7E6B3783 (UnityPlayer) FMOD::System::createSound
0x00007FFB7E0E3677 (UnityPlayer) LoadFMODSound
0x00007FFB7E0B57C9 (UnityPlayer) AudioClip::AwakeFromLoadThreaded
0x00007FFB7DD734F6 (UnityPlayer) PersistentManager::postReadActivationQueue
0x00007FFB7DD79B9F (UnityPlayer) PersistentManager::LoadObjectsThreaded
0x00007FFB7DC3DD49 (UnityPlayer) LoadSceneOperation::perform
0x00007FFB7DC3D1C1 (UnityPlayer) PreloadManager::Run
0x00007FFB7DC3D4C9 (UnityPlayer) PreloadManager::Run
0x00007FFB7DC999F8 (UnityPlayer) Thread::RunThreadWrapper
0x00007FFBBA042774 (KERNEL32) BaseThreadInitThunk
0x00007FFBBC7E0D51 (ntdll) RtlUserThreadStart

========== END OF STACKTRACE ===========

  • Cameron Baron

    Are you using the FMOD Unity Integration or the built in Unity audio?

  • Derek

    Hey, Cameron, thanks for responding! It’s the built-in Unity audio. There is basically one persistent audio source and one persistent audio listener. Honestly though, I can’t even find any documentation on CodecFSB5::readInternal to even begin to narrow it down. I’ve tried using a different song (the current theme is a WAV file, tried switching to an OGG, but nothing changed.) I’ve tried muting the sound altogether.

    Bizarrely though, the song is not stopped or paused. It simply plays the entire time. Even more bizarrely is that the song continues playing once the built-in Unity crash dialog pops up. Something that does seem suspicious to me though after looking at this stack trace is that Codec::read is called twice from the same place. Just seems… odd.

    Mainly just looking for any kind of direction on how to even begin to get a handle on this problem.

  • You must to post comments

If you are able to reproduce it I would definitely raise an issue with Unity on their tracker.
Unfortunately the version that Unity use is a modified version of FMOD 4 which we don’t have access to.

Nothing in particular stands out from what you have mentioned, but what does the Unity crash dialog say? If you have any other logging information we can try to help.

  • Derek

    Thanks again for the answer. I’d love to be able to provide a simpler repro project for Unity, but at the moment, it’s quite prohibitive in terms of time/effort when we have a looming deadline (like always, of course :P) And to be honest, there is probably 0% chance they’d look into this anytime soon given the relative rarity of it as I haven’t found a single mention of it online, despite it being a seemingly common practice–you know, persisting sound across multiple Unity scenes.

    That being said, I was not aware that FMOD was commonly integrated with Unity independently of the ‘built-in’ integration, or that there was a distinction. Can you elaborate more on why a developer would do this in the first place since Unity already has support for it? I have to admit, I’m somewhat confused by it. Does this mean that the functions that are in the call stack (CodecFSB5 etc.) aren’t actually native FMOD functions? How do you disable Unity’s already ‘native’ FMOD integration?


  • Cameron Baron

    So as I said previously, Unity are using an older version of FMOD which means that any changes or fixes since then have been made by Unity. Also Unity is using FMOD 4, while FMOD 5 is the most current.

    Using our plugin, you can gain access to the latest versions of FMOD and are able to integrate your project with FMOD Studio, which is an intuitive and flexible game audio middleware solution. If you have a sound designer, they will be using a tool like this to create all the sounds for your game. Or you can use the LowLevel API to load audio from file and have complete control over the created sounds.

    You can access the entire FMOD API through our C# wrapper, included in the Unity plugin, which you won’t have direct access to in Unity. This allows programmers more control over their audio system.

    The FMOD Unity integration can replace the built in audio for your entire game, you can disable the built in Unity audio in the editor menu:
    Edit->Project Settings->Audio->Disable Unity Audio

    In short, using the FMOD Plugin will give you greater control over your audio, both in design and in usage. Have a read through some of our docs, download and play around with Studio or the API, it may help you decide if it’s something that interests you and your team. Let me know if you have any other questions.

    FMOD is free for Indies!

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.