I don't know what's wrong with FHitResult



// Fill out your copyright notice in the Description page of Project Settings.


// Fill out your copyright notice in the Description page of Project Settings.


#include "Grabber.h"
#include "Engine/World.h"
#include "DrawDebugHelpers.h"

// Sets default values for this component's properties
UGrabber::UGrabber()
{
	// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
	// off to improve performance if you don't need them.
	PrimaryComponentTick.bCanEverTick = true;

	// ...
}


// Called when the game starts
void UGrabber::BeginPlay()
{
	Super::BeginPlay();

	// ...
	
}


// Called every frame
void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	FVector Start = GetComponentLocation();
	FVector End = Start + GetForwardVector() * MaxGrabDistance;
	DrawDebugLine(GetWorld(), Start, End, FColor::Red);

	//내가 설정한 원으로 콜리션 원 만들기
	FCollisionShape Sphere = FCollisionShape::MakeSphere(GrabRadius);
	
	FHitResult HitResult;
	bool HasHit = GetWorld()->SweepSingleByChannel(HitResult, Start, End, FQuat::Identity, ECC_GameTraceChannel2,Sphere);

	if(HasHit)
	{
		AActor* HitActor = HitResult.GetActor();
		UE_LOG(LogTemp,Display,TEXT("Hit Actor: %s"), *HitActor->GetActorNameOrLabel());
	}
	else
	{
		UE_LOG(LogTemp,Display,TEXT("No Actor Hit"));
	}

}

When I look elsewhere, I don’t get a message saying I succeeded in Hit, but I get a message. Why is that?

I also have a problem with Debugline currently not connecting to bpplayer but connecting in the x direction. Is it related to this?

Do you mean why do you get both? You likely have two grabbers in the scene, one on your player and one on something else that’s always hitting the gargoyle.

I’m not 100% sure what you’re trying to say but it could be that is the line trace of the other grabber you have,


You could log out the owner’s name as well to verify this.

I want Hit Actor to come out when I look at the stone, but Hit Actor comes out even if I don’t look at the stone, and no actor hit that comes out when I don’t look at the stone is also printed out, so I’m curious why it works like this.

	if(HasHit)
	{
		AActor* HitActor = HitResult.GetActor();
		UE_LOG(LogTemp,Display,TEXT("Hit Actor: %s"), *HitActor->GetActorNameOrLabel());
	}
	else
	{
		UE_LOG(LogTemp,Display,TEXT("No Actor Hit"));
	}

Grabber component has been added to stone statues only.

	FVector Start = GetComponentLocation();
	FVector End = Start + GetForwardVector() * MaxGrabDistance;
	DrawDebugLine(GetWorld(), Start, End, FColor::Red);

When I looked at the lecture, when I entered this code, a red line was drawn between the actors that added BP_Player and Grabber Component. But I didn’t draw with BP_Player, but I drew an X-coordinate line. Additionally, Grabber never added to any other actors other than stone statues.

Then it’s as I thought what you meant and I’ve given you the reason. The logs are coming from different grabbers. Change the log to add the owner

    if(HasHit)
	{
		AActor* HitActor = HitResult.GetActor();
		UE_LOG(LogTemp,Display,TEXT("%s has Hit Actor: %s"), *GetOwner()->GetName(), HitActor->GetActorNameOrLabel());
	}
	else
	{
		UE_LOG(LogTemp,Display,TEXT("%s has No Actor Hit"), *GetOwner()->GetName());
	}

I’m not quite sure what you’re trying to say with the other bit, could you show screenshots to aid?

What exactly does show screenshots to aid mean? Vscode? Epic?

Screenshots of the lines to aid me. To help me understand what you’re saying.


If you look at the output log in this picture, you can see the hit and no factors coming out at the same time even though you are not looking at the stone statue.

That’s the part of what you’ve said that I understand and have explained twice already. Did you modify the log as suggested to see what I mean?

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms