Ok, so I found out it’s when I move the LineTraceEnd block to the TickComponent method. Any idea why it’s doing this?
TickComponent():
void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
/// Get player view point this tick
FVector PlayerViewPointLocation;
FRotator PlayerViewPointRotation;
GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(
OUT PlayerViewPointLocation,
OUT PlayerViewPointRotation);
//Draw red trace in the world to visualize
FVector LineTraceEnd = PlayerViewPointLocation + PlayerViewPointRotation.Vector() * Reach;
// If physics handle is attached
// move object that we're holding
}
GetFirstPhysicsBodyInReach():
const FHitResult UGrabber::GetFirstPhysicsBodyInReach()
{
///Setup query parameters
FCollisionQueryParams TraceParameters(FName(TEXT("")), false, GetOwner());
///Line-trace (Aka ray-cast) out to reach distance
FHitResult Hit;
GetWorld()->LineTraceSingleByObjectType(
OUT Hit,
PlayerViewPointLocation,
LineTraceEnd,
FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
TraceParameters
);
///See what we hit
AActor* ActorHit = Hit.GetActor();
if (ActorHit)
{
UE_LOG(LogTemp, Warning, TEXT("Line trace hit: %s"), *(ActorHit->GetName()))
}
return Hit;
}