UE4:C++にてLineTraceにてオブジェクトの取得
LineTraceでオブジェクトの名前をLogに出すメモです。
ActorComponentでC++を作成しPawnのコンポーネントに追加しています。自分の環境では動きました。
自分用メモなので参考にしないでください。いずれどこかに移します。
LineTrace.h private: float DirectLength= 1000.f; LineTrace.cpp #define OUT void ULineTrace::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); FVector PlayerViewLocation; FRotator PlayerViewRotation; GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(OUT PlayerViewLocation, OUT PlayerViewRotation); FVector TraceEnd = PlayerViewLocation + PlayerViewRotation.Vector()*DirectLength; FHitResult Hit; GetWorld()->LineTraceSingleByObjectType(OUT Hit, PlayerViewLocation, TraceEnd, FCollisionObjectQueryParams(ECollisionChannel::ECC_WorldStatic)); AActor* HitActor = Hit.GetActor(); if (HitActor) { UE_LOG(LogTemp, Warning, TEXT("LineTraceHit:%s"), *(HitActor->GetName())) } // ...