Hello.
I have a project with two blueprints, both of them has a spawn sound component when I touch them with a line trace and what I want to do is stop the song when I shoot the other, start its attached song and vice versa.
I am using an Interface to communicate the First Person Character with the actors as it shows in the image.
I tried with the Cast to node, to communicate from one actor with the other and making booleans, but I failed and I cannot figure how to do it properly.
If anyone can help me I would appreciate it, thanks in advance.
Hi @DarkSturm_16
One thing to know about sounds is that they can be âFire and forgetâ (no way to stop them once playing)
But creating an audio component with âSpawn Sound at locationâ should allow you to control them.
Not sure what you mean about âmaking booleansâ - but try this:
If you have a function(âCustom Eventâ blueprint node) inside of that bp that just calls stop on the âSongâ Variable - you could cast to a specific BP class and call that function.
The âcastâ node input could be an âinstance editableâ âActorâ object reference. (To use the classes in your screenshot as an example, BullseyePowerMetal, BullseyeDeathMetal etc. are all different blueprints that inherit from âActorâ) - So the cast node is asking "Is this actor a BullseyePowerMetal? Yes, then open it up and call itâs âStopâ function.
There are better ways to set it up. (Like one parent âBullseyeâ class, and then configurable children for different genres)
Hopefully that helps. (I feel a bit rambly) I think once you grok how to set Blueprint References youâll be good. Let us know if you need more clarification though. Welcome to the Forums!
Hello and thanks for your answer.
I am unable to make the Cast to node working in the next example: first, I ââshootââ a line trace against the BullsEyePowerMetal, then the attached song starts playing but, when I ââshootââ another line trace against the BullsEyeDeathMetal it just changes its own material but the rest of the code does not work.
If I erase the Cast to node works properly but both songs (the PowerMetal song and the Death Metal song) plays at the same time and I do not want that scenario.
Obviously I am doing something wrong trying to cast between actors but I cannot figure how can I doing properly.
I attached the code of both actors and a video for a better ilustration of my problem.
Sorry if it is difficult to understand what I am trying to say, as english is not my native language.
Thanks in advance.
Desktop_2022_12_28_15_00_52_113.mkv (1.9 MB)
Hi @DarkSturm_16,
Your english is great, but this is one of those problems that I need to implement in-editor to figure out.
This sample shows a way to do this with one âhittable soundâ actor (With exposed variable to set) So youâd drag these BPs into your level and set the sounds individually.
AJ_HittableSounds.zip (1021.6 KB)
Hopefully this provides a better foundation, or at least has a tidbit or two you can add to your knowledge.
Thanks for your time, was a bit harder than I expected.
I included your code on my little project and now is working properly but with the exception that I am still unable to pause the songs after ââshootingââ different actors, so I need to work more and figure what is happening.
But I am satisfied with the result so thanks again!
1 Like