Add projectile lifespan to return object to pool if no collision
This commit is contained in:
parent
25efc64ebd
commit
53053d46a5
@ -56,6 +56,11 @@ void AProjectile::SetActorHiddenInGame(bool bNewHidden)
|
|||||||
if (bNewHidden)
|
if (bNewHidden)
|
||||||
{
|
{
|
||||||
ResetData_Implementation();
|
ResetData_Implementation();
|
||||||
|
GetWorldTimerManager().ClearTimer(ProjectileLifetimeTimerHandle);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GetWorldTimerManager().SetTimer(ProjectileLifetimeTimerHandle, this, &AProjectile::ReturnProjectileToPool, ProjectileLifespan, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,6 +115,14 @@ void AProjectile::OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedCompon
|
|||||||
RemainingDamagableEnemies--;
|
RemainingDamagableEnemies--;
|
||||||
|
|
||||||
if (RemainingDamagableEnemies == 0)
|
if (RemainingDamagableEnemies == 0)
|
||||||
|
{
|
||||||
|
ReturnProjectileToPool();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AProjectile::ReturnProjectileToPool()
|
||||||
{
|
{
|
||||||
AGameModeBase* gamemode = UGameplayStatics::GetGameMode(GetWorld());
|
AGameModeBase* gamemode = UGameplayStatics::GetGameMode(GetWorld());
|
||||||
|
|
||||||
@ -122,6 +135,3 @@ void AProjectile::OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedCompon
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -38,6 +38,12 @@ public:
|
|||||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
TObjectPtr<UNiagaraComponent> NiagaraRibbonComponent = nullptr;
|
TObjectPtr<UNiagaraComponent> NiagaraRibbonComponent = nullptr;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
|
float ProjectileLifespan = 15.0f;
|
||||||
|
|
||||||
|
private:
|
||||||
|
FTimerHandle ProjectileLifetimeTimerHandle;
|
||||||
|
|
||||||
// Sets default values for this actor's properties
|
// Sets default values for this actor's properties
|
||||||
AProjectile();
|
AProjectile();
|
||||||
|
|
||||||
@ -59,4 +65,7 @@ private:
|
|||||||
void OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
void OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||||
const FHitResult& SweepResult);
|
const FHitResult& SweepResult);
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void ReturnProjectileToPool();
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user