IgnoreActor not working on linetrace

Hi guys,

I am performing a line trace multi by channel on the visibility channel, with the code below, but the AddIgnoredActor line doesn’t seem to work - my character is still getting hit by its own shots.

Code:

bool Afpscharacter::MultiRaycastInCameraDirection(TArray<FHitResult>& ResultOutHit, float RaycastRange, ECollisionChannel CollisionChannel)
{


	//Start coordinates are in FPS camera
	FVector Start = FPSCameraComponent->GetComponentLocation();
	//Gets direction player is looking at
	FVector ForwardVector = FPSCameraComponent->GetForwardVector();

	//End coordinate is range away from start
	FVector End = Start + (ForwardVector * RaycastRange);

	FCollisionQueryParams CollisionParams;
	
	//Ignore ourselves
	CollisionParams.AddIgnoredActor(GetOwner());
	CollisionParams.bReturnPhysicalMaterial = true;


	//Performs raycast

	bool result = GetWorld()->LineTraceMultiByChannel(ResultOutHit, Start, End, CollisionChannel, CollisionParams);
	return result;

}

Log showing that I am hitting myself with my shots (as well as the enemy, labelled BP_Afpscharacter_1 or something, and I am BP_afpscharacter_0. I am also hitting a blocking cube.

[2022.08.26-18.09.07:168][345]LogTemp: Warning: Name = BP_Myfpscharacter_C_0
[2022.08.26-18.09.07:168][345]LogTemp: Warning: Name = BP_Myfpscharacter_C_1
[2022.08.26-18.09.07:168][345]LogTemp: Warning: Name = Cube_2

Perhaps you should ignore the array of actors. If your character has something like attaching a weapon or other object. It is they who collide to say exactly output to the log components for which the detection occurs.

Try something like:

void AddIgnoredActors
(
    const TArray< const AActor * > & InIgnoreActors
)

Also, make sure the Owner is really your character and not the Controller.

2 Likes

If you’re calling that function directly from the actor shouldn’t it be CollisionParams.AddIgnoredActor(this); and not (GetOwner())

2 Likes

Thanks hexdeveloper and Rumzie, that was the problem. (the playercontroller was being ignored, which obviously wouldn’t do anything)