# Ignore self using SweepSingleByChannel in C++

**URL:** <https://forums.unrealengine.com/t/ignore-self-using-sweepsinglebychannel-in-c/462575>\
**Category:** World Creation\
**Tags:** self-collision, unreal-engine, FeatureRequest, Physics, CPP, Blueprint, question\
**Created:** [March 18, 2020, 9:25am UTC](https://forums.unrealengine.com/t/ignore-self-using-sweepsinglebychannel-in-c/462575 "2020-03-18T09:25:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![LuisAlaguna](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/luisalaguna/32/570408_2.png) [@LuisAlaguna](https://forums.unrealengine.com/u/LuisAlaguna)\
**Post date:** [March 18, 2020, 9:25am UTC](https://forums.unrealengine.com/t/ignore-self-using-sweepsinglebychannel-in-c/462575/1 "2020-03-18T09:25:17Z")

</div>

Hi,

I’m trying to hard-code my **Blueprint** functions in order to improve the performance.

Unfortunately, when i try to pass the nex function to **C++** , it get that the character is damaged for its attack, when the **Blueprint** function does not.

 ![298005-bptocpp.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/1/6/3161590345fe02c4fb55ae0b9cdcdb3857d0ce41.jpeg)

Looking carefully in te function i get that `SphereTraceSingle` have a **bool** option to ignores the “actor” itself, but i don’t get how can i do the same thing in **C++** using `SweepSingleByChannel`.

How can i solve it?

---

<div class="post-metadata">

**Author:** ![LuisAlaguna](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/luisalaguna/32/570408_2.png) [@LuisAlaguna](https://forums.unrealengine.com/u/LuisAlaguna)\
**Post date:** [March 18, 2020, 9:49am UTC](https://forums.unrealengine.com/t/ignore-self-using-sweepsinglebychannel-in-c/462575/2 "2020-03-18T09:49:18Z")

</div>

The first thing that we can do to understand what is happening is going to the **Blueprint** ’s function definition:  
a short searching in **Google** (SphereTracebySingle UE4 C++) sends us to the [documentation](https://docs.unrealengine.com/en-US/API/Runtime/Engine/Kismet/UKismetSystemLibrary/SphereTraceSingle/index.html), there we can see where is the folder when we can find the respective file in the code: `Engine\Source\Runtime\Engine\Classes\Kismet\KismetSystemLibrary.h`. Here, we can see that the code name of this function is `SphereTraceSingle` and if we go to its declaration we will fine its parameters and its code:

```
bool UKismetSystemLibrary::SphereTraceSingle(UObject* WorldContextObject, const FVector Start, const FVector End, float Radius, ETraceTypeQuery TraceChannel, bool bTraceComplex, const TArray<AActor*>& ActorsToIgnore, EDrawDebugTrace::Type DrawDebugType, FHitResult& OutHit, bool bIgnoreSelf, FLinearColor TraceColor, FLinearColor TraceHitColor, float DrawTime)
{
	ECollisionChannel CollisionChannel = UEngineTypes::ConvertToCollisionChannel(TraceChannel);

	static const FName SphereTraceSingleName(TEXT("SphereTraceSingle"));
	FCollisionQueryParams Params = ConfigureCollisionParams(SphereTraceSingleName, bTraceComplex, ActorsToIgnore, bIgnoreSelf, WorldContextObject);

	UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
	bool const bHit = World ? World->SweepSingleByChannel(OutHit, Start, End, FQuat::Identity, CollisionChannel, FCollisionShape::MakeSphere(Radius), Params) : false;

#if ENABLE_DRAW_DEBUG
	DrawDebugSphereTraceSingle(World, Start, End, Radius, DrawDebugType, bHit, OutHit, TraceColor, TraceHitColor, DrawTime);
#endif

	return bHit;
}

```

From this code what is interesting for us is `bool bIgnoreSelf` and we can see this parameter is used in the `Params` variable when we use the `ConfigureCollisionParams` to create is as a `FCollisionQueryParams`; we use this parameters to control the trace.

We want to know what `ConfigureCollisionParams` doest, so we go to its declaration and we see it returns a `FCollisionQueryParams` variable with its configuration adding a `AActor` to the Actors’s ignored list; so, we get we need add the our actor to the paramet’s ignored list as we can find in the `FCollisionQueryParams`'s [documentation](https://docs.unrealengine.com/en-US/API/Runtime/Engine/FCollisionQueryParams/index.html):

```
FCollisionQueryParams Params(FName(TEXT("KnockTraceSingle")), true, Actor);
Params.bReturnPhysicalMaterial = true;
Params.bReturnFaceIndex = !UPhysicsSettings::Get()->bSuppressFaceRemapTable;

```

As our function pass a `AActor` as the instigator, we want also this actor to be ignored, as this actor is own character, so, finally we add this parameter to the `SweepSingleByChannel` function:

```
bool bIsHit = GetWorld()->SweepSingleByChannel(OutHit, SocketLocation, EndTrace, FQuat::Identity, ECC_WorldStatic, FCollisionShape::MakeSphere(LengthTraceValue), Params);

```

And it’s all.
