Hi, I want to play a sound when left mouse button is clicked and then stop when it’s released. I did it like this:
static ConstructorHelpers::FObjectFinder<USoundWave> sound(TEXT("/Game/Sounds/Sound"));
gunSound = CreateDefaultSubobject<UAudioComponent>(TEXT("GunSound"));
gunSound->SetupAttachment(RootComponent);
gunSound->Activate();
if (sound.Succeeded())
{
gunSound->SetSound(sound.Object);
gunSound->SetRelativeLocation(FVector(0.f, 0.f, 0.f));
gunSound->SetRelativeScale3D(FVector(1.f, 1.f, 1.f));
UE_LOG(LogTemp, Warning, TEXT("loaded sound"));
gunSound->Stop();
}
but It always throws an exception when I want do Play(). Since I can’t find it anywhere I’m asking here. Thank you in advance for any answers.