Hi. I have set up a blueprint that I am trying to replicate in C++. I can do the trace fine, but I’m struggling to get Hit information from the array as shown in the blueprint. Without it I cant use FHitResult.GetActor() or anything.
Are you getting a Crash or something? If so Please tell what it says.
Try this instead the foor loop:
UE_LOG(LogTemp,Warning,TEXT("MyTrace Num Hits: %d"), HitResults.Num() ); // Will appear in your Logs just for debuging if hit anything at all
for (FHitResult& HitData : HitResults)
{
if (HitData.GetActor()) // pointer check
{
AEnemy* enemy = Cast<AEnemy>(HitData.GetActor()); // Type Check
if (!enemy) return; // Pointer Check
enemy->Damage(10);
}
}
Aside from that make sure GetWorld() is valid everything else looks fine to me.