I would like to test whether or not the actor which was the initial target for a LineTraceSingleForObjects was indeed the hit actor or whether something got in the way.
TArray<AActor*> TargetableEnemies;
TArray<AActor*> ActorsToIgnore;
UGameplayStatics::GetAllActorsWithInterface(GetWorld(), UTargetable::StaticClass(), TargetableEnemies);
FVector TraceStart = GetMesh()->GetSocketLocation(FName("head"));
TArray<TEnumAsByte<EObjectTypeQuery>> TargetableObjectQueryTypes;
TargetableObjectQueryTypes.Add(TEnumAsByte<EObjectTypeQuery>(ECC_WorldStatic));
TargetableObjectQueryTypes.Add(TEnumAsByte<EObjectTypeQuery>(ECC_WorldDynamic));
TargetableObjectQueryTypes.Add(TEnumAsByte<EObjectTypeQuery>(ECC_Pawn));
for (auto TargetableEnemy : TargetableEnemies)
{
FHitResult Hit;
bool bHit = UKismetSystemLibrary::LineTraceSingleForObjects(GetWorld(), TraceStart, TargetableEnemy->GetActorLocation(), TargetableObjectQueryTypes, false, ActorsToIgnore, EDrawDebugTrace::Type::None, Hit, true);
if (bHit && /*Compare Hit actor to targeted actor */)
{
// do stuff
}
In words, I perform a line trace from the actor’s head to socket to every targetable enemy’s location. The hit can collide with stuff like walls (a world static object), so it is not guaranteed my out hit actor was actually the targetable actor (again, it could have been a wall).
FHitResult, however, returns has TWeakObjectPointer rather than *AActor. How do I do a comparison between these two things? This: Hit.Actor == TargetableEnemy
always fails since these two types are different, as does Kismet’s EqualEqual_ObjectObject()
.
TL;DR what do I replace /* Compare Hit actor to targeted actor/*
with?