#include "Player/InteractionComponent.h" UInteractionComponent::UInteractionComponent() { PrimaryComponentTick.bCanEverTick = true; } void UInteractionComponent::BeginPlay() { Super::BeginPlay(); } void UInteractionComponent::CheckForInteractable() { AActor* Owner = GetOwner(); FVector LineStart = Owner->GetActorLocation(); FVector ForwardVector = Owner->GetActorForwardVector(); FVector LineEnd = LineStart + (ForwardVector * InteractionDistance); FHitResult HitResult; FCollisionQueryParams QueryParams; QueryParams.AddIgnoredActor(Owner); bool bHit = GetWorld()->LineTraceSingleByChannel(HitResult, LineStart, LineEnd, ECC_Visibility, QueryParams); if (bHit && HitResult.GetActor() && HitResult.GetActor()->Implements()) { InteractedActor = HitResult.GetActor(); } else { InteractedActor = nullptr; } if (bShowDebugLine) DrawDebugLine(GetWorld(), LineStart, LineEnd, FColor::Red, false, 1.0f, 0, 1.0f); } void UInteractionComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); CheckForInteractable(); }