Cast to custom function

Hello,

I am trying to add in the Level blueprint a “Cast to” function from another blueprint (audio). The idea is that I want to stop/play or change the music in the level when entering the trigger box.
I can’t get it working since it’s always give me an error becouse I don’t know what to assign as “Object” in Cast To function.

Please see attached.

Thank you for your help!

the actor it’s not spawned. It’s already in the level when starts. I just want to add some actions to it like: Play/Stop and change music track.

Wow, worked like a charm!

The truth is I didn’t manage to understand correctly “Cast to” functions, but I’ll give my best.

Thx a lot for you help.

from another blueprint (audio)

How and where do you spawn / instantiate that actor?

If it’s in the level, just drag its reference to the level blueprint. Or, select it, and right click in the graph to make a reference.

No need to cast at all.

Image from Gyazo

Cast to

Casting is not about communication or functions.

To simplify it greatly: casting is test - when you cast, you attempt to treat the target as an expected type of an object. You still need a reference to that object, though.

Imagine a player bumping into something as they move. You do not know upfront what the player is going to run into but you can cast (test) whether it’s a tree or a house. If the test is successful and it was a tree, now you can treat that previously unknown object as a tree, and call its functions.

Thank you again to try and make it clear. The general idea for the function I have managed to understand. I have seen other threads and youtube videos to try to make it clear, but I’ve only seen cast to character functions.
What is not clear for me is if “Object” from the “Cast To” function is the object that makes the function possible (player for example by pressing a key) or it’s an object from the blueprint I call.
My logic is:
I am trying to call a function from a blueprint so I do “Cast To - blueprint”. In the blueprint where I cast I have some custom functions that I call (becouse I know what I want to make), but unreal is asking me: “object”? Now is the tricky part that I don’t understand.
For example, if you look above on my custom functions in the audio blueprint: TurnOFF and TurnON, I ask the “audio component” to do this.
Then, why when I am calling the custom function in another blueprint the “object” is not the audio component? Since that’s the one that I want to do this, only I am calling it from another actor.
…I hope I explained myself well :slight_smile:

Note:

  1. adding the audio component as object in “Cast To” function was not working, but dragging the whole actor like you said from scene did the trick…
  2. Switch song custom event is not done correctly, I asked about it in another thread. I have five songs and I would like to cycle throw them by pressing a key (2 in my case)
  3. I am not realy experienced with programming, but blueprints seems very intuitive, till you find something like this :)))

Cheers!