Download

Timer operations not working

Hi everyone, Im trying to set up a timer in c++ and after some timer iterations clear it, pause it or at least do something with the timer, the problem is that nothing seems to work. ClearTimer is not working, TimerExists returns false, and if I try to get information of the timer always returns -1. I try it using GetWorldTimerManager(), also using GetWorld()->GetTimerManager(), and also storing a reference of GetTimerManager() for later operations. I get with all methods the same results as I said before. I’m gonna paste the code that i’m implementing for illustrate all problem.


#include "Concept.h"

#include "AbilityAssaultWeapon.h"


AAbilityAssaultWeapon::AAbilityAssaultWeapon(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	static ConstructorHelpers::FObjectFinder<UBlueprint> Projectile(TEXT("/Game/Blueprints/BP_ProjectileSlowDown.BP_ProjectileSlowDown"));
	ProjectileClass = (UClass*)Projectile.Object->GeneratedClass;
	Cadency = 0.1f;
	Damage = 2;
	AbilityPercentageOfUse = 0.5f;
	MaxProjectilesPerBurst = 10;
	CurrentProjectilesSpawnedInBurst = 0;
}

void AAbilityAssaultWeapon::PostInitializeComponents(){
	Super::PostInitializeComponents();
	World = GetWorld();
}

void AAbilityAssaultWeapon::MainUse()
{
	if (World)
	{
		World->GetTimerManager().SetTimer(this, &AAbilityAssaultWeapon::MainUseBehavior, Cadency, true);
	}
}

void AAbilityAssaultWeapon::MainUseBehavior()
{
	GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Green, TEXT("SHOT"));

	if (CurrentProjectilesSpawnedInBurst < MaxProjectilesPerBurst)
	{
		//UWorld* const World = GetWorld();
		if (World)
		{
			FActorSpawnParameters SpawnParams;
			SpawnParams.Instigator = AbilityInstigator;
			AProjectile* ProjectileSpawned = World->SpawnActor<AProjectile>(ProjectileClass, GetActorLocation(), GetActorRotation(), SpawnParams);

			if (ProjectileSpawned)
			{
				ProjectileSpawned->InitProjectile(AbilityInstigator, this);
			}
		}
		CurrentProjectilesSpawnedInBurst++;
	}

	else
	{
		if (World)
		{
			World->GetTimerManager().ClearTimer(this, &AAbilityAssaultWeapon::MainUseFinishing);
			GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Green, TEXT("END"));
		}
	}
}

void AAbilityAssaultWeapon::MainUseFinishing()
{
	GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Green, TEXT("MainUseFinishing"));
	Activated = false;
	CurrentProjectilesSpawnedInBurst = 0;
}

i have the same problem, i updated mi project from 4.0 to 4.5 and now the ClearTimer function is not working, the timer start fine, but it don’t stop when i use the ClearTimer, i tried your both methods and have the same situation.