I am trying to Toggle a light after a specified Delay in Unreal 5.X. This is my approach:
void AC_LightSwitch_CodeOnly::ToggleLightAfterDelay(int32 DelayInMilliseconds) const
{
FTimerHandle Timer;
FTimerDelegate const& Delegate = FTimerDelegate::CreateLambda([]
{
UC_Logger::Warn("Light Switch Async fired UwU");
});
const UWorld* World = GetWorld();
const FTimerManager& TimerManager = World->GetTimerManager();
float Delay = DelayInMilliseconds / 1000.0F;
>> TimerManager.SetTimer(Timer, Delegate, Delay, false, -1.f); // No viable function
// Function is missing const qualifier
}
At the marked line I receive an compiler error telling me there is no matching overload... but I just cant understand ...
The overload im trying to use is:
inline void SetTimer(FTimerHandle& InOutHandle, FTimerDelegate const& InDelegate, float InRate, bool InbLoop, float InFirstDelay = -1)
I also tried removing the const
from the Delegate
tried around a lot, but I just can't get an idea why it's telling me that. Delegate is a const.
Here's the tooltip from Rider for the issue: Tooltip
And for better code readablilty a screenshot of this section: Colored Codeblock
Thanks to you guys I found the root of my error.
Just like you said I could not find a viable function because FTimeManager
had a const
qualifier.
I did not quiet understand the relation why the const of a variable influences the way I find overloads. :)
Removed it and now it works, here's the new code:
void AC_LightSwitch_CodeOnly::ToggleLightAfterDelay(const int32 DelayInMilliseconds) const
{
FTimerHandle Timer;
const FTimerDelegate &Delegate = FTimerDelegate::CreateLambda([]
{
UC_Logger::Warn("Light Switch Async fired UwU");
});
const UWorld* World = GetWorld();
FTimerManager& TimerManager = World->GetTimerManager();
const float& Delay = DelayInMilliseconds / 1000.0F;
TimerManager.SetTimer(Timer, Delegate, Delay, false);
}
Thank you all and have a great day!