I stick with floats

I prefer using floats to int for health values. Instead of comparing the health to 0, I simply check if the health would become lower than 0, like so:

float ATank::TakeDamage(float DamageAmount, struct FDamageEvent 
                        const & DamageEvent, class AController * 
                        EventInstigator, AActor * DamageCauser) {
  
  float AppliedDamage = DamageAmount;
  if (Health - DamageAmount < 0) {
    AppliedDamage = Health;
    Health = 0;
  } else {
    Health -= DamageAmount;
  }

  return AppliedDamage;

}
1 Like

I thought it was weird to convert to ints too. Though you should do <= rather than just <

True, i noticed in my testing that i’d applied 8 dmg beause of that (instead of the corrct amount).

Hi Daniel
how I can use TSubclassOf<>(). As I know it is a reference of class and return UClass. but if I want to pass UDamageType pointer to ApplyRadialDamage() function how can I do it, because function don’t get UDamageType pointer.

 UGameplayStatics::ApplyRadialDamage(
		this,
		ProjectileDamage,
		GetActorLocation(),
		ExplosionForce->Radius,
		UDamageType::StaticClass(),  // require only UClass
		TArray < AActor * >()  
		);

I did something like:

TSubclassOf<UDamageType> DamageClass = UDamageType::StaticClass();
UDamgeType *Damage;
Damage = GetWorld()->SpawnActor<UDamageType>(DamgeClass);

but Damge pointer is not appropriate for ApplyRadialDamage()

What are you trying to do? Why are you trying to spawn a damage type?

As i guess UDamageType Class is a character of Damage and in that case if I want to use this parameter to pass ApplyRadialDamage() how can I do it. Ben set here UClass pointer, but if I want how can put here UDamageType pointer
Because one parameter of ApplyRadialDamage() is TSubclassOf < class UDamageType > DamageTypeClass, and in my mind here we can put UDamageType pointer

That’s not what the code you posted is doing though, that’s trying to spawn a damage class. That’s not related to ApplyRadialDamage.

You would need do something like this

UPROPERTY(EditDefaultsOnly)
TSubclassOf<UDamageType> DamageClass;

On the tank and pass that into the projectile class by some means

ahhh it’s available only through the Unreal Editor. thank you Dan

Privacy & Terms