In the function Grab(), we have
void UGrabber::Grab()
{
// Do the line trace
FHitResult HitResult = GetFirstPhysicsBodyInReach();
UPrimitiveComponent* ComponentToGrab = HitResult.GetComponent();
AActor* ActorHit = HitResult.GetActor();
if (ActorHit != nullptr) {
PhysicsHandle->GrabComponent(ComponentToGrab, NAME_None, ComponentToGrab->GetOwner()->GetActorLocation(), true);
}
}
We are retriveing both ComponentToGrab and ActorHit from HitResult, which is redundant. I think we can just get rid of ActorHit and do this
void UGrabber::Grab()
{
// Do the line trace
FHitResult HitResult = GetFirstPhysicsBodyInReach();
UPrimitiveComponent* ComponentToGrab = HitResult.GetComponent();
if (ComponentToGrab != nullptr) {
PhysicsHandle->GrabComponent(ComponentToGrab, NAME_None, ComponentToGrab->GetOwner()->GetActorLocation(), true);
}
I tried it and it worked the same as it was using ActorHit.