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?
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
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.
Should be noted though, if you untick “Auto Destroy”, which is on by default, then they will build up…