I have a weird issue with FTimerHandles. I created a simple handle so that I can fade out a sound when the player releases a button. There is a delay of 0.5 seconds, and the timer is activating and ending properly, as after the 0.5 seconds that I press the button, the sound stops playing from the correct function.
But when I try to use ‘IsTimerActive()’ it always returns false, even in the time where I expect it to be true, inbetween the 0seconds to 0.5 seconds.
And oddly enough, when I use GetTimerElapsed(), the function returns -1 as expected when the timer is not being run, but when it is being run, it doesn’t seem to run at all. It doesn’t return anything in the logs. It’s like, the function just refuses to return anything.
void AMRR_TargetNote::StopNoteLoopSound()
{
UE_LOG(LogTemp, Log, TEXT("Activating timer to fade out"));
GetWorldTimerManager().SetTimer(NoteLoopSoundFadeTimerHandle, this, &AMRR_TargetNote::ConfirmStopNoteLoopSound, NoteLoopSoundFadeTime, false);
}
void AMRR_TargetNote::ConfirmStopNoteLoopSound()
{
UE_LOG(LogTemp, Log, TEXT("Timer Finished"));
NoteLoopSound->Stop();
}
void AMRR_TargetNote::UpdateNoteLoopSoundVolume()
{
if (LastGunController != nullptr)
{
float FadeTimerVolume = GetWorldTimerManager().GetTimerElapsed(NoteLoopSoundFadeTimerHandle);
UE_LOG(LogTemp, Log, TEXT("FadeTimerVolume = %f"), FadeTimerVolume);
//Timer to fade away
if (GetWorldTimerManager().IsTimerActive(NoteLoopSoundFadeTimerHandle))
{
if (FadeTimerVolume != -1) //Handler returns -1 if not used
{
float FadeTimerVolumeNormal = (1 - FadeTimerVolume) / NoteLoopSoundFadeTime; //Normalize using full time from 1 to 0
UE_LOG(LogTemp, Log, TEXT("FadeTimerVolume = %f"), FadeTimerVolumeNormal);
NoteLoopSoundVolume *= FadeTimerVolume;
}
}
//Final Sound Volume Result
NoteLoopSound->SetVolumeMultiplier(NoteLoopSoundVolume);
}
}
Output Window
[2021.01.02-00.34.36:607][296]LogTemp: FadeTimerVolume = -1.000000
[2021.01.02-00.34.36:619][297]LogTemp: FadeTimerVolume = -1.000000
[2021.01.02-00.34.36:632][298]LogTemp: FadeTimerVolume = -1.000000
[2021.01.02-00.34.36:644][299]LogTemp: Activating timer to fade out
[2021.01.02-00.34.37:145][339]LogTemp: Timer Finished
[2021.01.02-00.34.44:533][924]LogSlate: Updating window title bar state: overlay mode, drag disabled, window buttons hidden, title bar hidden