PlayOnAwake Audiosource will only play when it's set to loop? bug?
I've been searching the forums, and asking some questions, but no one has been able to help me.
I have a situation that is perplexing. I have used this same method several times and it's not a complex setup, but it simply won't work in this specific scenario, and I can't pinpoint the reason.
I have a prefab of a gate, it has an audio source in a disabled game object in its hierarchy.This audio source game object is enabled via an animation when the player walks close to the gate.
The object is set up like this:
The system works as expected, when the character walks to the door it plays the animation, and it opens or closes the gate accordingly. HOWEVER, the audio will NOT play, even though the audiosource is set as "play on awake" and the gameObject IS being enabled in the editor. All other audio in the game works fine, and even other audio triggered in similar ways work too.
The audio in the prefab is set up like this: Weirdly, I found out that if I do set the audiosource to "LOOP" as shown on the image above, the audio DOES play, but I don't want this sound to be looping. No matter what audio clip is set, it will not play when not looped.
I have tried with an intermediary script triggered from an animation event as well, but although the method is also triggered, the audio source will not play, no matter what. I've set the volume and the range of the audiosource to be exaggeratedly large, to test, but nothing.
As I said, with the script, the functions are also triggering as expected, debug shows calls to the audiosource.Play() function too, and It shows in inspector as well.
I am at a loss as to what could be causing this.
I recently updated to unity 2019.1.9f1, but I'm not sure if this is a documented issue. Is this a bug? does anyone have any idea as to why it could be failing? Thanks.
Answer by Bdelcast · Jul 09, 2019 at 11:37 PM
After several restarts both PC and Unity, and even a unity re-installation, the issue seems to have resolved itself.
Not sure what did it.
Thanks anyhow.
Your answer
![](https://koobas.hobune.stream/wayback/20220612204624im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Audio Fade In / Fade Out with Trigger 0 Answers
Audio doesn't want to play 1 Answer
How do i make Unity seamlessly loop my background music? 5 Answers
Cannot Figure out How to use panStereo 0 Answers