Announcement

Collapse
No announcement yet.

Triggers and long sound cues

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Triggers and long sound cues

    Hey all,

    I've used Google to find an answer to my question, but to no avail. I thought it might be a simple trick, but I've had no success in tracking it down. I'm just starting out, and love to figure things out on my own, as best as I can. Here is my dilemma: I have a box trigger configured to play a sound when you walk over it. The challenge is, if I walk over the same trigger again, it plays the sound again. This is expected, however, the sound I chose is long, and when I walk over the trigger repeatedly, the sound plays over the sound before it. As you can imagine, if I run over the trigger ten times, I have ten sounds playing, all overlapping one another.

    I believe I am looking for a simple "if, then" blueprint where I can tell the trigger these two things:

    - If the trigger is engaged, and the sound is not currently playing, then play the sound; AND
    - If the trigger is engaged, and if the sound is already playing, do not play another copy of the sound

    I do want this to be a persistent trigger. I do not wish to use a 'do once' or have the actor 'destroyed' permanently - I want the above functionality if at all possible. Of course, if these commands are required for the purpose of a smart blueprint, then I'll chalk this up to a learning experience, and work with what you have.

    Thank you so much, in advance!

    Rick

    #2
    Originally posted by Rick Elphinstone View Post
    - If the trigger is engaged, and the sound is not currently playing, then play the sound; AND
    - If the trigger is engaged, and if the sound is already playing, do not play another copy of the sound
    Now, I'm not bumping my own thread, but I wanted to provide a short update... Here's the thing. I've been testing with pop-up text events, and have figured out how to toggle visibility, and NOT toggle visibility using a BRANCH to figure out if it is 'on' or not. So, long story short, I AM still working on this, and I THINK I may have a solution.

    ...and in true old guy on a forum fashion, I won't abandon this thread once I've figured it out - I'll post my solution with some information on how I got to where I got, successfully, for the future generations.



    Thanks!

    Rick

    Comment


      #3
      Hi Rick!

      So, just to be clear, you don't want to STOP the sound when the player moves off the trigger, correct? You just want to make sure another sound isn't playing if the first one is still going?

      As far as I know, there is no method in blueprints to check if a sound is playing. I don't have the editor available to me this second so I couldn't attempt a solution myself but it seems like this post might have what you're looking for:

      https://answers.unrealengine.com/que...of-the-so.html

      I would start by creating a "IsPlaying" boolean (Default: False). Then, instead of the "begin play" event, you would be using your overlap event. Immediately have a branch to check the value of "IsPlaying". If it's true, do nothing. If it's false, duplicate what is shown on the post to begin playing the audio then set "IsPlaying" to true. Then instead of printing the current percentage to the screen, have a branch to check if the percentage is >= 1. If it's not, do nothing. If it is, set "IsPlaying" to false as the audio has completed.

      Hope this helps! And if not I can load up the editor later today and reproduce the issue for a more precise solution.

      Comment


        #4
        Originally posted by Chumble View Post
        So, just to be clear, you don't want to STOP the sound when the player moves off the trigger, correct? You just want to make sure another sound isn't playing if the first one is still going?
        Correct! I'm using the event (as it is at the moment) for a sound cue that will play when the player hits the trigger, and if he runs back onto it, it won't re-engage an additional time while it's still playing. (I'm still learning, and want to use this for scripted voice-over and text in the future. I want the player to be able to revisit the same trigger, but I need it to give the ability to not have the same audio play over and over itself.)

        Originally posted by Chumble View Post
        I would start by creating a "IsPlaying" boolean (Default: False). Then, instead of the "begin play" event, you would be using your overlap event. Immediately have a branch to check the value of "IsPlaying". If it's true, do nothing. If it's false, duplicate what is shown on the post to begin playing the audio then set "IsPlaying" to true. Then instead of printing the current percentage to the screen, have a branch to check if the percentage is >= 1. If it's not, do nothing. If it is, set "IsPlaying" to false as the audio has completed.
        That's it! I had a bunch of tweaking to get it all right, but that works wonders. Here's the present blueprint I'm working with:



        To better help understand it, and for the 'future generations' who want to do this, here's what the blueprint does...

        SOUND CUE:

        I added a variable, "Playing Or Not" and check for it at the beginning of the trigger. As it has not run before, it's set to FALSE, and spawns my sound cue which starts playing. It sends it's notification that it is, in fact, playing, which sets the "Playing Or Not" variable to TRUE. So now, if the player engages the same trigger, it registers as TRUE, and sets a manual delay before resetting the variable to FALSE again, and allowing the sound cue to be replayed. (At this time, I couldn't determine a better method than to have a manual delay in there, so this is what I've got.)

        POP-UP NOTIFICATION:

        I set the TextRender Actor to invisible, so it did not appear in the scene. Once the trigger is activated (in my blueprint, it's enabled once the music starts playing - you can set yours as a separate process if you wish) it checks to see if it's visible, and if it's not, it toggles the visibility to make the text appear, followed by a delay, and then disappear once the delay runs out. If the text was already visible when the trigger is engaged, it bypasses the visibility toggle (as the text is already visible, it doesn't need to do it again), runs the delay and then finally, toggles the visibility off again, making the text invisible.

        I know there may be a lot of different (aka "better") ways that I could have done this, but I'm happy with it for now! Of course, if anyone has any ideas on how to improve on this, I'd love to see them.

        Thanks again for all of your help!

        Rick

        Comment


          #5
          HMMM
          Ok, so there IS a "Is Playing" node when you drag off the sound cue. Interesting .. I didn't know that existed. In that case, this solution is overkill and a bit messy.

          To clean this up, I would do the following

          In your viewport, add an Audio Component and set your sound file there.

          On your overlap trigger, get a reference to the audio component (drag it from the components panel to your blueprint). Drag off this component and create an "Is playing" node. If it's true, do nothing. If it's false, drag off the audio component again and execute a "Play". This eliminates the need for a "PlayingOrNot" boolean and the delay - it should dynamically work regardless of the audio length.

          For the text renderer visibility, I would prefer "Set Visibility" over "Toggle Visibility" because it makes it clearer and less error prone.

          Comment


            #6
            Originally posted by Chumble View Post
            HMMM
            Understatement of the day, I'm sure!

            Originally posted by Chumble View Post
            Ok, so there IS a "Is Playing" node when you drag off the sound cue. Interesting .. I didn't know that existed. In that case, this solution is overkill and a bit messy. To clean this up, I would do the following: In your viewport, add an Audio Component and set your sound file there. On your overlap trigger, get a reference to the audio component (drag it from the components panel to your blueprint).
            AH HA! THIS was the piece I was missing. I had seen so many links in the past couple of days showing the Audio Component in the blueprints as this small node, however, I could not replicated how to build it. THANK YOU!

            Originally posted by Chumble View Post
            Drag off this component and create an "Is playing" node. If it's true, do nothing. If it's false, drag off the audio component again and execute a "Play". This eliminates the need for a "PlayingOrNot" boolean and the delay - it should dynamically work regardless of the audio length.
            IT WORKS amazingly well, and just like you said. To the people reading this, I'll leave the above there as an example of what not to do, but here's a significant improvement, thanks to Chumble:



            Chumble, if there's ANYTHING ELSE you'd recommend, I'm all ears. This is exactly what I was hoping to do, and cleaning this up was amazing.

            Originally posted by Chumble View Post
            For the text renderer visibility, I would prefer "Set Visibility" over "Toggle Visibility" because it makes it clearer and less error prone.
            I'm working on this right now. THANK YOU AGAIN!

            Rick

            Comment


              #7
              You're welcome! Only other thing I'd change (and this is just personal preference) is I would only get one reference to the Audio Component and drag from that one to both the "Is Playing" node and the "Play" node, this way it cleans up some clutter. It does the same exact thing, just removes the need to get the same reference twice. And if you double click on the wire, you can add a "Reroute" node to help arrange the wires cleaner. But if you find it easier to see it this way, by all means keep it this way.

              Definitely feel free to ping me with any other issues if you need it. I don't check the forums too often but I get notifications to my email if I get a message so I'll see those.

              Comment


                #8
                Originally posted by Chumble View Post
                You're welcome! Only other thing I'd change (and this is just personal preference) is I would only get one reference to the Audio Component and drag from that one to both the "Is Playing" node and the "Play" node, this way it cleans up some clutter. It does the same exact thing, just removes the need to get the same reference twice.
                Ah, that's good to know. Thank you!

                Originally posted by Chumble View Post
                And if you double click on the wire, you can add a "Reroute" node to help arrange the wires cleaner. But if you find it easier to see it this way, by all means, keep it this way.
                Oh, man. I did NOT know how to do the rerouting nodes. Google is a tough mistress when you don't know the terminology you're looking for. I've added these, as well as the different recommendations you've made, and think I have a pretty good idea on how it all comes together:



                Originally posted by Chumble View Post
                Definitely feel free to ping me with any other issues if you need it. I don't check the forums too often but I get notifications to my email if I get a message so I'll see those.
                I'll try not to bug you directly! I definitely appreciate all of your feedback in this thread. I'm getting more comfortable as the days go on. (This is probably my second week trying my hand at blueprints... I think with they help you've given so far, you've answered a lot of the questions I think I should have, going forward.)

                Thanks again!

                Rick

                Comment

                Working...
                X