Play sound once movement ends?

I am trying to add a DING sound to play once an elevator stops moving. How could I go about this? Everything I tried makes it so that the DING sound occurs immediately after the elevator starts moving as opposed to once it stops.

I assume youā€™re using a timeline? Then you can use the ā€˜finishedā€™ pin.

No I have the movement set using begin/end overlap and just manually set the Z-value for each floor level.

Hey @ssophia_lee! Just like clockwork stated, one of the easiest ways to pull this off would be a simple timeline like so.
image

That said in your implementation of the elevator from the other port of yours, it may look a bit different. Youā€™d have to make a way for it to detect itā€™s at the proper location. I always advise against putting checks like that in your event tick as it will run indefinitely, but to tack an end state on quickly to your other implementation Iā€™d do something along the lines of checking the position of the elevator and if itā€™s at the correct location play the sound. Since youā€™ve already got a nearly equals check in there, Iā€™d just slap a Do Once node after that and have it only reset when a new button is hit.

Is there no other way to add the sound with what I have now? I am searching up timeline tutorials and it seems like it would be quite complicated to make an elevatorā€¦

Oh thereā€™s a myriad of ways to pull it off, some requiring more structural changes than others. I work from C++ usually so I have to transfer that knowledge to BPs so it takes me a bit. Iā€™ll write up a little tester in a few!

1 Like

Alright, so I think the simplest method from looking at your other script is probably this.

Basically taking your signal you already had to determine where to stop the elevator, making that do once, then taking the false condition as the reset for the do once. Let me know how that works for ya!

1 Like

We donā€™t actually know what you have now, that would help :slight_smile:

Hey @eblade! I recognized the username from another post the night before so I put 2 and 2 together, this is the original post about the elevator, you can see where I appended my code there at the end. UE4 Using Widgets as an input source?

ok, so, first off, I completely disagree with the way youā€™re doing this. But, without making major disruption to what youā€™re doing there, what I think you want to do is ā€¦

You know when the elevator stops, because you set the direction to 0. Add a ā€œRun Onceā€ node after that, connect your ā€œPlay Soundā€ to that. Then wire the ā€œFalseā€ on that branch before you set the direction to 0, to the ā€œResetā€ pin on the Run Once.

So, when you stop, it hits the Run Once, which plays the sound. Then when it starts moving again, it resets the Run Once, so it will play again the next time it stops.

All of that said, I would approach this from like a completely different direction. Iā€™ve not had the opportunity to create an elevator in Unreal 4 yet, but I think Iā€™d try to make something that is much more easily reusable and easier to setup, by doing something likeā€¦

Make an elevator Actor. Give it the usual static mesh component to represent the elevator itself. Add a Box component to it, that represents the area that it can move through, and then make a custom Component (call it like FloorMarkerComponent or some such), which you can add as many of as you need. Add one by default to it.

On BeginPlay, query for all of the FloorMarkerComponents that are owned by the Elevator, storing their location into an array ordered by their floor numbers. Then you just have an array that has all of the locations, and when you press whatever button corresponds to the floor, you can just set the destination by like Destination = FloorArray[FloorNumber].

Then when you want a new elevator, you just size the box component through the entire shaft it will travel, add a FloorMarkerComponent at each location you want it to stop, and youā€™re basically done.

As far as your movement goes, Timeline would be better to use to implement it, but is also a bit less straightforward to figure out. Itā€™s a tool worth knowing, though, as itā€™s built exactly for handling things like that.

That said, if you keep moving it around in Tick, it would be an optimization to turn off Ticking on the whole thing when you reach a destination, and then turn it back on when you start moving again. That would also prevent needing to use the Run Once before the Play Sound.

Good luck. If you try out any of my ideas, Iā€™d love to know how they work, since like I said, Iā€™ve never implemented an elevator in UE4+, so I wonder if my gut feel idea there would work / work well, or if it would just be a pain.

(i also just had a thought, if your floors are all standard heights, you wouldnā€™t even need the FloorMarkerComponent, you could just have a ā€œnumber of floorsā€ and a ā€œamount of space between floorsā€, do some simple math, and youā€™re there)