How can I make audio start/stop through an ability that the player is using?

I’m a sound designer whos very new to unreal/bluprint programming and am working on a project that requires audio to start when a player uses an ability and stop when the player stops using the ability. So far I’m able to have the sound play when the ability is used but I can’t get it to stop when the player stops the ability despite the fact I’ve created an audio component vatiable and set it up to the sound cue thats playing.

Also when I test it I get this error:
“Blueprint Runtime Error: “Accessed None trying to read property GrabAudio”. Node: Stop Graph: EventGraph Function: Execute Ubergraph BP Player Ability Grab Blueprint: BP_PlayerAbilityGrab”
So I’m not sure if I maybe havent set up the variable properly or something like that?

Please let me know if you have any suggestions and thanks in advance.

I see you setting the variable, and then using it. So I’m assuming that this code only exists when then player is either starting to use an ability or stopping?

Then the variable would not be valid. The variable doesn’t live indefinitely in between uses of the component ( or whatever it is ).

Have you tried starting and stopping the sound from inside the player?

I’m not totally sure how I would do that since the bluprint for the ability is in a separate bluprint.

Am I correct, though? The reference stops existing in between?

I’m not the person who coded the ability itself so I can’t be entirely sure I’ll try to find that out. Its a bluprint class and I cant see anything that would indicate that the code stops existing but the event for the ability has a parent event if that explains it at all.

1 Like

Ah, tricky then…

if somebody else coded and you don’t want to mess with it too much, what you could try is just figure out where you want the sounds and call an Event Dispatch there.

You can make another class - like maybe an actor component to add to the game mode, which will bind to these events and then you can have all of your audio related stuff taken care of there.

This way your audio is separated from the rest of the code - it only necessitates that events are dispatched at the right time. Both the class which outputs the events and your listener only need to know about an intermediary class which houses the events. Of course, you can have them directly know about each other as well.

I managed to find out that the code does in fact not exist when it isnt being used.

1 Like

Just curious, but what is the structure to the left off the screen? It looks to me like the Stop is executed before the SpawnSound call, which would mean the variable is empty (null) at the time of the stop call.


Here ya go

There is definitely a way to access that offending variable before it is called. If something is calling Terminate before Activate is called, then the variable is null (or nothing) because it hasn’t been created yet.

There is an easy way to verify this and several ways to solve it.

To verify, set a breakpoint at the offending variable location, then from the debug menu select Blueprint Debugger and look at the stack trace. It will tell you how you got there. If I am correct, then you will have gotten there from Terminate.

One easy way to fix this is simply move the node. The blue arrow below shows the way in I mentioned, and the red arrow shows where to drag that pin to in order to be sure it won’t get in there without first being activated.

  • Edit: I am not sure you want to do the false side of that branch on Terminate (I didn’t look to see what is there), so you may need to instead make a copy of that branch condition that only terminate uses with nothing attached to the false. If you need more help understanding what I mean let me know and I will post another picture of it.