Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Discussion AudioSource.PlayClipAtPoint and pooling

Discussion in 'Audio & Video' started by Stranger-Games, Sep 5, 2023.

  1. Stranger-Games

    Stranger-Games

    Joined:
    May 10, 2014
    Posts:
    392
    Hi,

    I noticed that AudioSource.PlayClipAtPoint creates 'One shot audio' object each time it's called and it gets destroyed automatically.

    I'm sure I can build a custom solution of pooling audio source prefabs that gets spawned at the location and get back into the pool after sound stops, but I wanted to ask if there's any built-in way to pool that?

    Thank you for advance.
     
  2. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    290
    Hi!

    There is currently no built-in way to do this, but it's a fun thing to implement :)

    Personally I like to have a "SoundEmitter" object that carries multiple AudioSources and enable/disabled them based on the need. You can keep a global emitter for all 2D sounds, which is where you get the best improvement. For 3D sounds it's a bit less relevant in my opinion, unless you have a moving object with multiple sounds emitted at the same time.
     
    Stranger-Games likes this.