- Home /
AudioSource.PlayOneShot performance
Hi,
I want to know your views on the performance differences between the use PlayOneShot() and creating/destroying AudioSources (and subsequently assigning audioClips to these sources then playing them) at runtime.
Which method would you guys recommend to play short clips (for SFXs) with performance in mind?
Thanks
Answer by Jesse Anders · Mar 02, 2011 at 04:28 AM
I can't really comment on the performance characteristics, but I'd imagine that the overhead of repeatedly creating and destroying game objects will generally be greater than that of reusing the same game objects (search the forums for 'pooling' for further discussion on this).
I use pooling for audio sources, and that's worked well for me. (Specifically, all audio playback requests go through a central audio manager that creates persistent 'audio channel' game objects as needed. These objects persist between levels, so they're never destroyed; they're just reused repeatedly.)
Hi Jesse, thanks for that. Just curious, do you use PlayOneShot in your persistent 'audio objects' or a combination of all available audio source playback methods?
When a 'sound playback request' comes in (consisting of e.g. audio clip, position, volume, pitch, loop, etc.), I find an available 'sound channel' (which is just a game object with an audio source attached) or create one if needed, assign the clip, position, volume, pitch, etc. to it, and then invoke Play(). So in answer to your question, Play() is used, rather than PlayOneShot().
Your answer
Follow this Question
Related Questions
compress recorded audio in an app? 0 Answers
Audio.Pitch not smaller than 0.1f on the iPhone? 1 Answer
Making a GetComponent array 1 Answer
help with iphone 3GS performance (polys and audio) 2 Answers
Large level loading best practices 1 Answer