Play a sound once on event tick used as a Linetrace by Channel

Hi guys! I have the next question.

I’m using a tick event for a LineTraceByChannel emulating the mouseover event with a ray. Everytime that the ray hit on an specific object a sound should be triggered once.

When I put the node “Spawn sound attached” to play the sound it plays but in a loop. So, i thought about to use “DoOnce” node.

If I use the “DoOnce” node the sound plays once but then not anymore and I need that this sound plays everytime that the ray hit on the object.

I don’t know how to setup the “reset” property of DoOnce because if i use a Branch asking if the sound is playing it doesn’t works.

Any clue?? Thanks!!!

Once your trace hits a object, store that object in a variable class.
Before playing your sound, check if your current target is different from the previous one (the one in your variable class). This way, your sound will be played only when you’re hitting a new target.

You should have your NotePlayer as a separate actor in the world. This should have a bool indicating whether or not it is playing. Set the boolean to true when it is told to play, and set it to false after the minimum reset time.

If the bool is true when it is told to play, use a branch to not play the note.

Then when you mouse over the NotePlayer, call the play note function you’ll create. Then it can only be called once until the minimum reset time has elapsed.

Hi guys! thank you so much for the help. Finaly i solved it doing another Raytrace that evaluate the name of the object that is hit and then if the name is equal to the object name that has to play a sound, i Spawn the sound with DoOnce. If not, it reset and works good.

Now i have another problem. I need to do this with several objects so I was thinking to use an Array, but i don’t know how to do it. May you help me with that please?

Thank you!

I couldn’t make an array, so i solved it with a chain of “or” one after another.
I close the question. Thank you again!!

You should mark the answer that solved your question upvote the ones that helped, and add your solution as an edit to your question.