I am trying to get the actor which was hit by my projectile. I would like to cast that to a class called ‘target’. Here is the code for that: (I have indented the line where the casting actually happens)
void AProjectile::OnHit(UPrimitiveComponent *HitComp, AActor *OtherActor, UPrimitiveComponent *OtherComp, FVector NormalImpulse, const FHitResult &Hit)
{
// Only add impulse and destroy projectile if we hit a physics
if ((OtherActor != NULL) && (OtherActor != this))
{
OtherComp->AddImpulseAtLocation(GetVelocity() * 100.0f, GetActorLocation());
UE_LOG(LogTemp, Error, TEXT("Actor name %s"), *OtherActor->GetName());
ATarget *TestTarget = Cast<ATarget>(*OtherActor);
if (TestTarget != NULL)
{
UE_LOG(LogTemp, Warning, TEXT("Dead"));
TestTarget->DamageTarget(50.f);
}
Destroy();
}
}
The Actor is lying on the pointer *OtherActor. I tried de-reference the pointer but it did not work. Instead I got this message in the message log:
C:\Unreal Projects\Seasons\SeasonsGameAlpha\Source\GunMechanicsV2\Projectile.cpp(46) : error C2665: 'Cast': none of the 3 overloads could convert all the argument types
Any Tips?