I Find Casting Unbearably Challenging

Hi Unreal Community!

I’m an audio artist that is fairly new to Unreal, and I’m finding I’m constantly stuck on casting. I specifically find it endlessly difficult to find the input object I need.

I’m trying to stop a piece of audio. I have created a blueprint notify to store my logic in. I believe that, from within this blueprint notify, I should cast to my UAC_ActorAudio. From within the UAC_ActorAudio I should be able to get a reference to the piece of audio being played, and then pull in the reference into my blueprint notify to stop it.

Here’s the actor:

The issue I have is I don’t know what object reference to give the cast within my custom blueprint notify. How do I logically deduce what it is? Many thanks in advance! I’ve tried watching tutorials on this, but the ones I’ve seen only cover more simple cases such as using a player pawn.

You have to know what information you need and what object holds it. The cast just tells the engine of what type the object actually is. You don’t cast to get anything, you need to have the reference to the object. So if you want to cast to UAC_ActorAudio, you already need a reference to UAC_ActorAudio, as the cast is just telling the engine that the object you have is of type UAC_ActorAudio.

For example: You play an audio with CreateSound2D. This node returns a reference to the sound object, which you can store in a variable, i guess, thats what you use UAC_ActorAudio for. But to get your UAC_ActorAudio later on, you need to store a reference to it in a variable somewhere, where you can access it. For example in the PlayerCharacter or GameInstance or GameState. If you always use your UAC_ActorAudio you dont even have to cast to it. Just make the variable of type UAC_ActorAudio.

So, if you store it in PlayerCharacter for example, you can use GetPlayerCharacter to get a reference to the PlayerCharacter object. Now you need to cast that PlayerCharacter object to your PlayerCharacter blueprint type. So the engine knows what variables and functions this PlayerCharacter object has. From there you can just get the variable with your UAC_ActorAudio.