Here’s what I want to do:
When the player interacts with a button, I want my Audio Player Device to play a sound for the instigator only. I have marked the device “Instigator Only.”
@DolphinDom told me that Activate() isn’t enough, I also have to RegisterPlayer(Player) first, in order for the device to recognize the instigator. And then after the sound plays I need to UnregisterPlayer.
I can’t just do
AudioPlayer.RegisterPlayer(Player)
AudioPlayer.Activate()
AudioPlayer.UnregisterPlayer(Player)
Because putting UnregisterPlayer right after Activate will immediately cut off my Audio Cue before it can finish. So I need to script a pause for the duration of the Audio Cue, using Sleep. But Sleep requires a suspends context, which I can’t do inside Player function. So I need to write a separate function and spawn it inside of my Player function.
Below this is what I tried, but my audio gets cut off. Maybe it’s not good to spawn a function that only has Sleep() in it, maybe you need to put the thing that you want to happen after Sleep inside of the suspends function? But I can’t because UnregisterPlayer is a Player function.
UISpawnEffects(Player:player):void = {
AudioPlayerUISpawn.RegisterPlayer(Player) #
AudioPlayerUISpawn.Activate()
Logger.Print("Audio Activated")
spawn {WaitForUISpawnAudio()}
AudioPlayerUISpawn.UnregisterPlayer(Player)
}
WaitForUISpawnAudio()<suspends>:void = {
Sleep(UISpawnAudioLength)
}
Could someone explain how to fix this? Thanks in advance!
Why does Epic require us to use RegisterPlayer and UnregisterPlayer along with Activate anyway, when Instigator Only is checked on the Audio Player Device? Playing audio for for a player who presses a button should be super simple and instead it’s a big unintuitive ordeal that requires multiple functions and a parameter specifying the Audio Cue length. I noticed that @xCUBDd had trouble with this same feature recently. How do I call methods from inherited class?