Problems with reading the result of a line trace

I am trying to cast a Line using an ActorCompnent towards the owner of the component and print the name from anything that collides with it.
It keeps printing “None” which would suggest that the line tracer simply doesn’t find anything, which would be weird. But it does report that it finds something.
Can anyone help me with this?

	FHitResult Hit;

	float RayLength = 100.0f;

	FVector StartLocation = GetOwner()->GetActorLocation() + FVector(0.0f, 0.0f, 1.0f) * RayLength;
	FVector EndLocation = StartLocation - FVector(0.0f, 0.0f, 1.0f) * RayLength;

	FCollisionQueryParams CollisionParameters;

	bool isHit = GetOwner()->ActorLineTraceSingle(Hit, StartLocation, EndLocation, ECollisionChannel::ECC_PhysicsBody, CollisionParameters);
	DrawDebugDirectionalArrow(GetWorld(), StartLocation, EndLocation, 5.0f, FColor::Red, false, 0.01f, 0, 1.f);

	FString name = Hit.BoneName.ToString();

	if (isHit)
	{
		if (GEngine) GEngine->AddOnScreenDebugMessage(0, 2, FColor::Green, name);
	}

The component/actor it should collide with uses the PhysicsActor Collision Preset.

I am fairly new to Unreal so bear with me :sweat_smile:.

I do not know about the layout of your scene. But I have two suggestions, the first one is that reviewing the collision presets and be sure the blocking will raise, the second one is to check the RayLength if realy what you want. (RayLength = 100 means 100cm not 100m)

I changed the collision channel it now is:

bool isHit = GetOwner()->ActorLineTraceSingle(Hit, StartLocation, EndLocation, ECollisionChannel::ECC_WorldStatic, CollisionParameters);

The red line is the DebugDirectionalArrow.
As you can see it pierces through the cube, and I set the cube to block all (Including WorldStatic)

Ah… You supposed that the BoneName is none which is weird? I misunderstanded before. The BoneName is none here should be normal. Because there is just a StaticMeshComponent rather than SkeletalMeshComponent. If you want which object was hit, you could refer the Actor field in FHitResult, and Hit.GetActor().GetName() for the object’s name. Or you could use the return value of ActorLineTraceSingle method to judge if the hit was raised.

I use your code to test. The isHit is true. I think it is what you want.


Yes, it’s not hitting a Skeletal Mesh, so there are no bones. So the Bone it hits is None.

As suggestion please use draw debug lines with the same input in order to understand your line trace is hitting something.

DrawDebugLine(GetWorld(), LocationTwo, LocationThree, FColor::Emerald, true, -1, 0, 10);

And then check the collision presets of your object is actually BLOCKING for your ECC_PhysicsBody.

Advice, from the PhysicsBody output I understand that you want to use some custom channel.
You can do it by in your projects header file as

#define COLLISION_CUST_PHYSICS   ECC_GameTraceChannel1

Troubleshoot as like this. It will give you some strong clue about problem.

Yes, Thank you that was the problem!