Does "Spawn Sound Attached" pile up over time when not being destroyed?

Hi again,

as seen in the title → does the node “Spawn Sound Attached” pile up attached sounds if called repeatedly and not being destroyed after each call when playing is done?

Example blueprint:

I don’t know how to check out if it does which is why I am asking here.

Thank you for helping up front :slight_smile:
Chris

I don’t know how to check out if it does

Looking at your example, SpawnSoundAttached returns an object, that somehow should describe this sound. You may store this pointers in array and check them for IsValid (or any other internal checks on object, if presents).

Should also be noted, that there is a possibility they will live till next GarbageCollection, so something like gc.CollectGarbageEveryFrame 1 is adviceable when checking this

1 Like

Yes, I know about the return pin, the gc.CollectGarbageEveryFrame 1 thing I didn’t really get. It seems to constantly log something.

My question is just wether or not I am supposed to destroy the sound when it’s repeatedely called to prevent sound objects piling up. For tests I did destroy it with an “is valid” node before that and didn’t receive complaints in the output log.

No it won’t pile up forever it will eventually get collected with the garbage, so if you’re not making a lot of spawn calls it should be fine.

I do personally think it’s better if you are going to be making a lot of calls to spawn the sound you are better off simply creating the object with a sound component already attached then calling play on the sound instead, this way you don’t need to keep making spawn calls. Or if the object isn’t moving then you can simply “PlaySoundAtLocation” as another option, saves you from spawning the full component each time.

Not trying to tell you how to suck eggs, you probably have a reason for doing it the way you are and if you’re not trying to milk every frame for performance then you should have no problem with the way you doing it, it won’t overflow with sound components. :grinning_face:

Should be noted though, if you untick “Auto Destroy”, which is on by default, then they will build up…

1 Like

Thanks a lot! That answered everything I needed to know :slight_smile:

And yes, I have a reason for doing it like that because just by attaching an audio component to a BP actor doesn’t keep audio in sync with motion, sadly. (As seen here: UE5: How to get sound effects in sync with moving (timeline) actors?)

1 Like