I need to come up with a BP that makes it so that when the player can press E to activate and deactivate individual objects which have separate sounds.
Example : Triangle shape plays fire sound when E key is pressed in proximity, when E key is pressed again it stops …playing.
Circle shape plays water sound when E is pressed in proximity , it also stops when E is pressed again.
Circle and triangle can also both be pressed in successive order when in proximity and will each …individually play their sounds, they can also both be stopped whenever they are clicked on again.
Optional: I need to know how to make Objects/Shapes change colour on key press.
Make the Audio you want to play as an Audio Component in the BP. Put a Sphere component on the Blueprint and set it to the radius you want the object to be interactive at. Add events for the sphere component: OnComponentOverlapBegin and OnComponentOverlapEnd. Plug these into a Gate Node. Begin into Open and End into Close. Take the “other actor” option from the overlap nodes, click and drag them out and Cast to [yourCharacterBpNameHere]. This makes it so that when the player overlaps the sphere component, something can happen.
Next, you make a Blueprint Interface Node and plug up both the Character and ShapeBP together. There are many tutorials for this with video instructions for passing messages from one BP to another. You will take the event and plug it into the Gate Node, then into a branch with a “is Playing” bool attached to keep track if the audio component is playing or not. Reference the Audio Component and make a Play and Stop node from it. Plug the Play node to the False section of the Branch (and add a Set “isPlaying” to True Node); Next add the Stop node to the True section of the branch(and add a Set “isPlaying” to False Node).
Now when the event from the player comes in while he is overlapping the sphere component and the bool ‘IsPlaying’ is False, it will Play the audio and set isPlaying to true, and vice versa.
Tried to follow you indications but as I’m fairly new to the engine it failed. Here is a screenshot of what i attempted to do.
Maybe you can explain to me why it doesn’t seem to be working.
Take the execute line from OnComponentBeginOverlap and plug it through ‘Cast to My character’ before putting it into the Gate.
Do the same thing for OnComponentEndOverlap through its ‘cast to mycharacter’ and into Close.
I didn’t know there was an IsPlaying node. Since it returns if the sound is playing, that looks like you wont have to make another bool variable! Plug that into the Branch.
If you are hearing the sound, then that means the sound must be on auto activate. Take that off and now that you can interact with it, you should be able to turn it on and off. Sorry for the late response!