I’m running the following code:
void AFEWeapon_Projectile::FireWeapon()
{
const FVector StartTrace = GetMuzzleLocation();
const FVector ShootDir = GetAdjustedAim();
SpawnProjectile(StartTrace, ShootDir, true, FColor::Red); //Set debugging manually if desired
}
void AFEWeapon_Projectile::SpawnProjectile(FVector Origin, FVector Direction, bool debug, FColor debugcolor)
{
ActiveProjectiles.Add(FProjectile(Origin, Direction, ProjectileVelocity, debug, debugcolor));
}
void AFEWeapon_Projectile::UpdateProjectiles()
{
int i = 0;
for (FProjectile fp : ActiveProjectiles)
{
fp.Update(GetWorld());
i++;
//Process hit results after the projectile has been updated
}
UE_LOG(LogTemp, Warning, TEXT("Loop iterations: %d"), i);
}
FHitResult AFEWeapon_Projectile::WeaponTrace()
{
return FHitResult();
}
void AFEWeapon_Projectile::ProcessHit()
{
}
void AFEWeapon_Projectile::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
UpdateProjectiles();
}
This is supposed to update the TArray
ActiveProjectiles. However the logging from UpdateProjectiles()
looks like this:
LogTemp:Warning: Loop iterations: 0
LogTemp:Warning: Loop iterations: 1
LogTemp:Warning: Loop iterations: 0
LogTemp:Warning: Loop iterations: 1
LogTemp:Warning: Loop iterations: 0
LogTemp:Warning: Loop iterations: 1
Why is this happening? It also seems to be causing the calls to Update()
for my USTRUCTS to not work properly. What causes the loop to run inconsistently? Is tick a bad method to use here?