What is the difference between spawn sound at location and play sound at location?

I have some trouble understanding the difference between them two.

Visually I can see that the last parameter on spawn sound has a “auto destroy” bool parameter and the play sound has a “owning actor” parameter. Some people mentioned that the play sound doesn’t destroy itself, but that sounds nonsense to me, if that would be the case then this is susceptible to memory leaks.

Mainly I’d like to know how do these two nodes differ.

2 Likes

Hi @eshkor, welcome to the forum. The spawn method does return a reference to the audio component to you, so you can manipulate it later on, while the play method just is a ‘fire and forget’.
I also remember some course on the Epic Learning site mentioning, that the play method is a little bit cheaper.
And in case the sound should move with an actor (scene component), there’s a SpawnSoundAttached method as well.

5 Likes

Hey @herb64, thank you for the welcome.
I see that spawn method has the bool for auto destroy. If the bool is set to false it will not be destroyed and can be reactivated if needed, as mentioned in the description. So basically if I check false and the spawn method is activated over and over it will be generating me audio components. Does UE handle this auto somehow to clean the unused components after some time or do I need to be mindful and always have a part that destroys the references to not overflow? Which method could I use to destroy the references?
Also, thank you for mentioning the spawn sound attached method, I’ll have to play with it.

If auto destroy is not checked, the Audio Component remains and you can destroy it using the DestroyComponent function. There’s no destroy timer. It may get subject to Garbage Collection if not referenced at any point any more, but that’s not directly under your control.

destroy-component

In case you just want an audio component to be used over and over for an actor, I would recommend not to spawn components over and over (this also creates overhead) - you also can just add an audio component to it like this:

audio-comp

1 Like

Interesting, will experiment with destroying the components to see how it works.
I did try to add an audio component to the mesh, but I didn’t understand how it works for event based sounds and went to play/spawn sounds at location after it is triggered. As now it is known for me how they work I’ll get back to learn how it to work with sounds under mesh in the hierarchy. But I don’t want to flood this page as it is going out of scope from the initial question.

Thank you for answering my questions. I want to know how the engine and methods work on a bit deeper level so this has helped me a lot.

I need a little more clarification, because although I’ve read and understood the responses, when I try to spawn a sound, I hear nothing. When I just play the sound, that’s when I hear something.

Does spawning a sound not automatically trigger it? As in, it needs to be activated like a visual Niagara effect?