To give a brief rundown of this issue:
In my weapon class I declare a TArray of projectiles.
TArray<AUTProjectile*> CurrentCount;
This allows me to iterate through all of my projectiles and blow them up simultaneously, find the count of projectiles, etc.
My projectiles will blow up if they take any damage though. Based on my logging it looks like after my projectile is destroyed my CurrentCount array is not updated, so I need to update CurrentCount to remove the pointer to my projectile before it’s destroyed. What I’m doing is this.
float AUTProj_Grenade::TakeDamage(float DamageAmount, struct FDamageEvent const& DamageEvent, class AController* EventInstigator, class AActor* DamageCauser)
{
if (EventInstigator != NULL)
{
AUTCharacter* UTP = Cast<AUTCharacter>(EventInstigator->GetPawn());
AUTCharacter* UTOwner = Cast<AUTCharacter>(Instigator);
if (UTP != NULL && UTOwner != NULL && (UTP->GetTeamNum() == 255 || UTP->GetTeamNum() != UTOwner->GetTeamNum()))
{
OwningGrenadeLauncher->ClearGrenade(this);
Explode(GetActorLocation(), FVector::UpVector);
}
}
return Super::TakeDamage(DamageAmount, DamageEvent, EventInstigator, DamageCauser);
}
The ClearGrenade function is currently defined as so:
void AUTWeap_GrenadeLauncher::ClearGrenade(const AUTProj_Grenade& ClearedGrenade);
{
for (int32 i = 0; i < CurrentCount.Num(); i++)
{
if (ClearedGrenade == *CurrentCount[i])
{
CurrentCount[i]->ShutDown();
CurrentCount.RemoveAt(i);
}
}
}
At the moment I think this is conceptually sound, but my C++ syntax here is getting me some compilation errors. I’m not really sure what to make of this since it’s seemingly to do with my function declaration.
1>UnrealTournament\Public\UTWeap_GrenadeLauncher.h(36): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
UnrealTournament\UnrealTournament\Source\UnrealTournament\Public\UTWeap_GrenadeLauncher.h(36) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I could probably handle this by keeping a separate int32 value for CurrentCount and refactoring ClearedGrenade to simply decrement this int32 value, rather than using CurrentCount.Num() to return the number of projectiles I have active. That being said, I’d prefer to handle it this way so I am not duplicating unnecessary information. Anyone able to point me in the right direction here?