Error when trying to toggle active a sound cue

Hello,
I have found that there is an error that pops up whenever I try to toggle whether or not a sound cue is active. I have some screenshots. I’m not exactly sure what’s wrong or how to fix this.

Thank you for looking.

Before you access the audio component call the “IsValid?” node to make sure it’s a valid audio component before you use it. Somewhere you are calling DestroyActor to destroy the audio component and you are maintaining an old reference to the destroyed audio component.

Does toggling whether or not the spawned audio is active delete the spawned audio?

Not to my knowledge, it doesn’t.

Can you post screenshots of your blueprint code where you are accessing the audio component and assigning a sound to it. If you could also show me the details panel for the audio component in question that would help me reproduce this locally to give you better support.

I think I already have- untitled.png. Here it is again, anyways.

Sorry I didn’t see the second image embedded in your original post – my bad.

Are you destroying this MainMenu_Widget when this error occurs?

At which point are you executing this chain of function calls? Is it during the Widget’s Construct event or a custom event fired on a button click? When are you calling your StartMusic event?

In order for me to reproduce this I need a clear understanding of how to reproduce your exact design :slight_smile:

MainMenu_Widget Never gets destroyed. The sound is spawned when the Main Menu is constructed. The custom event is a button click, that is set in the same widget. Thanks again.

ok well I think the problem is that your StartMusic event is accessing the return value of SpawnSound2D after the EventConstruct ends. This means the return value of SpawnSound2D won’t be available. After you spawn your sound immediately promote it to a private variable within your widget so your other events can use the sound reference.

There are two problems with your setup.

The first is that you need to store the reference of the spawned sound in a variable in your widget. This will allow other events in your widget to access the spawned instance.

The second issue, which caught me by surprise, is when you call SetActive and set it to false in a Widget blueprint, it does actually destroy the audio component that was created.

Below is a working solution, I was able to reproduce your issue and solved by using the SetVolumeMultiplier node to basically turn off/on the volume of the audio component instead of calling SetActive. I also stored the audio component reference into a class variable.

For the record, calling SetActive and setting it to false does not destroy the audio component when the audio component is added as a component to a PlayerController or any other Actor.

What worked for me is when spawning/creating the 2D sound, disable “auto destroy”, in the drop down menu.