Should I Use IsA to check class type

I am very new to Unreal Engine and coding in C++, and I’m wondering if I should use the IsA<> method for checking the class type of an actor instead of casting. Is it better for performance, or should I cast instead?

My code looks like this:

void ATD_MinigunTower::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (OtherActor->IsA<ATD_Projectile>) return;

if (GEngine) GEngine->AddOnScreenDebugMessage(-1, 1.5f, FColor::White, TEXT("Overlapping!"));

Targets.Add(OtherActor);

}

Any feedback would be greatly appreciated!

You should only use IsA if you are certain the pointer is valid and you only want to know the type without using the type otherwise use Cast.

3 Likes