AudioSource not playing at different scene

I’m having a weird issue with AudioSources. I made a second AudioManager class besides the existing one, both instantiate AudioSources and plays them when called. But the AudioSources from the second manager don’t play.

The game has a “main scene” that have all the managers and is always on, and the level/menu scene with the game itself. In the “main scene” it’s the AudioListener and the AudioSources are always in the gameplay scenes, it works 100% and I never had issues.

Now I created AudioSources in the “main scene” itself, but I can’t hear the audio from them no matter what. The problem is that (after debuging and checking the Profiler) the audio is playing, BUT in the profiler the Time for that audio is stuck at 0. I have no idea whats happening and the AudioSources are set with “ignoreListenerPause = true” (and the AudioListener is not paused) so I have no idea how this is happening and only with the the scenes besides the gameplay one.
I’ve tried to change the AudioListener and the AudioSources to dummy scenes for testing, but the situation continues. I can hear the audios from the gameplay scene but not from others.

To be fair I’m not using 2021-3-LTS, I’m currently using 2021-3-18f1.

I play the audios from the animations, the animation calls a event in a frame and the event function calls the Manager class to play the audio.

TLDR: How is it possible for my AudioSource to be “isPlaying = true” and stay frozen at “Time = 0”? Even if I set “ignoreListenerPause = true” and the AudioListener is not even paused. (Also, doesn’t seem like I’m calling it to play non stop).

Have you tried reproducing this with a minimal example? For instance, create an empty base scene that only plays audio, then load additional scenes to check whether the audio still works.

Try that first, then gradually add elements from your main game to identify exactly when the audio stops playing. It could be a misconfiguration on your side, which a minimal setup will reveal, or a script that isn’t behaving as expected, which you’ll likely discover as you reintroduce your game objects into the simplified scene.

Are you sure you are telling the Instantiated copy to play and NOT the original prefab you cloned it from?

If you did the latter, a) it won’t work, and b) you should see a warning in the log about it.

Probably will do this, it seems to be a problem in my code that’s doing this.

Oh, maybe I should remove this part of the text, it’s confusing. I meant to ssay that I reused a class for the AudioManager that I made to make a second AudioManager class (ScreenAudioManager). I didn’t use any prefabs.
And I think the fact that I created a new class from an existing one is not very relevant to the problem

Then it just sounds like you wrote a bog-standard bug… and that means… time to start debugging as Meredoth suggested above.

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.

This is embarrassing, the pitch was set to zero so that’s why I couldn’t listen (found out looking at isVirtual that was set, turns out the audio system was culling due to the 0 value for pitch).

The reason why this happened is because I set an array of structs that is used to set the audio source values on creation, and as the default value for integers is zero and I forgot to set it to 1 after filling in the editor it created the AudioSource and set the pitch to zero (usually you don’t have to take this care when instantiating AudioSources from editor, because it start with a default 1).