|
Post by DarkTonic Dev on Nov 27, 2014 6:16:05 GMT
This is a great question from an email we received. Good information to have! - - - - - -
Hi - can you please clarify how pooling works in Master Audio? It looks like MA creates a bunch of AudioSources at runtime for each possible instance of a sound (each sound group's Weight), but this could create many, many sources in the scene (it's not unreasonable for a game to have 150 sound effects, with 5 or so variants each. That's 750 AudioSources sitting in the scene, which will be idle most of the time).
Normally when I think of pooling, I'd expect something like the scene to have 10 or so AudioSources that get reused with different clips and positions each time we want to play a sound.
If MA works how it looks like it does, is there any impact of having that many idle AudioSources in the scene at once? (I've just done a quick test and it looks like 700 idle AudioSources adds about 10MB to a build's memory footprint - not too bad). Does this cause any other problems for anyone? Or is this usually OK, and Unity handles large scene hierarchies?
Cheers!
|
|
|
Post by DarkTonic Dev on Nov 27, 2014 6:16:45 GMT
Our answer:
I see what you're saying. The main reason for wanting / using Pooling is to avoid the performance costs associated with Instantiate and Destroy and the Garbage Collection that occurs from them. Master Audio indeed never Instantiates or Destroys anything except during Scene startup. But yes, you are correct. Things are not reused for different purposes (except as the individual Variations are slightly tweakable at runtime). Someone once asked if we could make all the Variations that weren't playing disabled Game Objects. But I did a prototype, and it didn't seem to have any effect on audio memory (more below on this). Anyway, this wouldn't really be feasible to do with Audio Sources moving around between Variations. It would probably hurt the performance a fair bit because it would become Instantiation of components.
A high number of Audio Sources doesn't seem to matter much. What matters a lot more is how many of them are playing. If there are more than 32 playing, then the prioritization feature of Unity will take over and cull the rest. The "extra" Audio Sources with the same Audio Clips assigned don't take up any extra audio memory (or very little if your tests are more extensive perhaps) or performance when they're not playing. They are paused and do nothing. Also, all the scripts we have on those Variations do not run any code except when audio is playing, so it scales nicely with hundreds of sounds. We have about 150 sounds in our 2nd game, which is almost released.
You will find that with a lot of audio, the most important thing to do is to use Resource files for (probably) all music and a lot of infrequently played SFX. The audio you set up as Resource files in Master Audio will take up zero memory except while they are playing.
I'll do some more testing about "extra" Audio Sources in Unity 4 and 5 and see what's more correct.
|
|
|
Post by DarkTonic Dev on Nov 27, 2014 6:17:20 GMT
I did some more profiling. On Unity 3 and 4, it costs about 0.8 Kb of audio memory for each additional "clone" that gets created for weights > 1 of Variations. So adding about 700 clones for polyphony reasons adds only about 0.6Mb. Insignificant really.
However it gets even better. You'll be extremely excited to hear (as I am) that the extra clones take exactly zero additional audio memory on Unity 5!
Bring it on Unity!
|
|