Hello. I need help with following setup:
I have Ambient Sound positioned in the level. It should be activated once when I pull a lever.
I have tried to do it like this:
→ Get All Actors with Tag (“LeverSound”)
→ Get (0)
→ Cast to AmbientSound
→ Get Audio Component
→ Play
But it doesn’t work. The problem is between Cast to AmbientSound and Play (I have checked with PrintString).
I also have tried to just add a Play Ambient Sound at Location node, but it always plays 2D at players spot.
Firstly, please provide a screenshot of the BP or the code you use so we can help you.
You are assuming you only have one actor with tag “LeverSound” which might not be correct - check what is the return from Get All Actors with Tag.
Try using Get All Actors of Class instead. This way you are sure you are getting the correct class and your cast can’t fail.
Try removing the cast altogether. Any actor can have an Audio Component. If you are sure you have selected the right actor don’t cast.
Best: make an Ambient Sound Actor variable in your lever object - assign the correct actor after you’ve placed the lever in the level and call play directly. You skip the tag, the search in the level and the cast.