I tried not using the FTimerHandle Time variable and pass FTimerHandle() directly in the SetTimer method
GetWorld()->GetTimerManager().SetTimer(FTimerHandle(), this, &AProjectile::OnTimerExpire, DestroyDelay);
And I got this error
error C4239: nonstandard extension used: ‘argument’: conversion from ‘FTimerHandle’ to 'FTimerHandle &'
and
note: A non-const reference may only be bound to an lvalue
If I change this code to
FTimerHandle Timer = FTimerHandle();
GetWorld()->GetTimerManager().SetTimer(Timer, this, &AProjectile::OnTimerExpire, DestroyDelay);
or the Timer without FTimerHandle() constructor I get no compiler errors, but I cannot understand why this works.
I also tried using the Destroy method of AProjectile directly in the SetTimer method
GetWorld()->GetTimerManager().SetTimer(Timer, this, &AProjectile::Destroy, DestroyDelay);
But I got this error
error C2664: ‘void FTimerManager::SetTimer(FTimerHandle &,TFunction<void (void)> &&,float,bool,float)’: cannot convert argument 3 from ‘bool (__cdecl AActor::* )(bool,bool)’ to 'void (__cdecl AProjectile::* )(void)'
and
note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
I just do not understand this too, isn’t Destroy AProjectile’s method too?
Are those errors C++ errors or just something that comes with Unreal Engine 4?
Thanks in advance.
P.S. I am new in C++, that’s why I am asking those questions, as I am trying to get a better understanding.