Is there a way to instantiate a new FHitResult on the stack that I can store in an array as data I will work with? In this example function, I am reading it a “TArray” array prepared to handle FHitResult pointers from the stack that I can manage:
void ATheCharacter::Raycast_FullEngines(TArray<FHitResult*, FDefaultAllocator> ta_hits, TArray<UStaticMeshComponent*, FDefaultAllocator> ta_thrusters)
{
//GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Yellow, FString::FromInt(ta_thrusters.Num()));
for (int i = 0; i < ta_thrusters.Num(); i++)
{
FVector PawnLoc;
FRotator PawnRot;
FVector StartPos;
FVector EndPos;
EndPos.Set(100.0f, 100.0f, 100.0f);
StartPos.Set(0.0f, 0.0f, 0.0f);
PawnLoc = ta_thrusters[i]->GetComponentLocation();
PawnRot = ta_thrusters[i]->GetComponentRotation();
FVector Start = PawnLoc;
FVector End = PawnLoc + PawnRot.Vector() * 500.0f;
FCollisionQueryParams traceparams(ForceInit);
**FHitResult* temphit = new FHitResult();**
GetWorld()->LineTraceSingle(*temphit, Start, End, ECC_GameTraceChannel1, traceparams);
DrawDebugLine(GetWorld(), Start, End, FColor(255, 0, 0), true, 10, 0, 3);
ta_hits.Add(temphit);
//GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Yellow, FString::FromInt(ta_hits.Num()));
}
}
Does anyone know a way to instantiate things in such a way in UE4 so that I can have access to the memory and objects on my own so I can pass them around in various ways for usage? Thanks!