SurfaceEffect Audio create a new AudioSource for every impact event

Kirshor

Member
Hi,
I tested play an audio when an object fall to a ground by using trajectory. It work Ok as I expected but I recognized that the audio source is instantiated as a new child of the Game object for every impact event. It's not a pooled object so it will remain in the scene until end of the game. I think the problem is when 1000 impact event is fired that will create 1000 Audio Source that will consume the game's memory !?
Correct me if I'm wrong, please.

Thank you very much.
 
How exactly are you spawning these AudioSources? If you are literally manually spawning a new AudioSource when the object collides with the ground, then that is not a very clean way of doing it as you'll end up with hundreds of game objects and it may end up affecting performance (although an AudioSource by itself doesn't really use up much memory when it's not actually playing a clip).

If I understood correctly, can I ask why you're using this method rather than just using the surface system to play an audio clip when the object collides with a particular surface? This video nicely demonstrates how to set this up:

 
Yeah, I'm wrong. SurfaceSystem just create 1 AudioSource. I misunderstood because the Collision Mode I set in the TrajectoryObject is reflection, that make the item collide many time with the ground so I saw many the AudioSource.
SurfaceSystem is really a powerful system!
I just expect there is a way to control the volume of all instantiated AudioSource in 1 place. For example, there is a volume value or an AudioMixer input in the AudioManager, that will control all the (MAX) volume of the AudioSource. Could you implement that in future?

Thank you very much.
 
Top