Author Topic: NGUITools.PlaySound hijacks audio source to play UIPlaySound sounds  (Read 2447 times)

Holy Manfred

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 8
  • Posts: 71
    • View Profile
I have a slider that makes a sound (through UIPlaySound) when moved. The more the slider gets moved the more the sound gets pitched.
I had to investigate an issue where my background music got pitched up instead of the UIPlaySound component when I was moving the slider. That made things sound pretty weird :)

It is not really a bug I guess, but the way NGUITools.PlaySound() finds its audio source to play sounds can cause some odd behavior. I have a gameobject in my scene which has my audio logic script, an audio listener and an audio source used for background music. NGUI just looks for any audio source on the listeners gameobject and uses the first one it finds. It only adds a new source when none is found.
In my case this leads to my music audio source getting modified by a pitch I set on any given UIPlaySound component.

It can be worked around by adding an empty audio source component and move it to the top of the component list but it might be nice to have a clean way to specify to NGUI which audio source to use.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUITools.PlaySound hijacks audio source to play UIPlaySound sounds
« Reply #1 on: February 04, 2017, 03:34:58 AM »
You should consider placing your own audio sources somewhere other than on the same object as the listener. Even a child object of that listener will work fine. That said, I can certainly add a public static value you can explicitly set in NGUITools.