SweepMultiByChannel always returns player

Well, I have searched google and it seems that most people have an opposite problem. I am would not normally put this under bug reports, but since I have tried absolutely everything I can think of, I shall do so (of course if there is some coding error, please let me know). I have set up in the custom AI Controller a sphere trace that goes straight out from my enemy pawn (basically a line of sight). I have done this many times before (although one time I did have the same issue, but I cannot remember the solution).

Code here:

const FVector dir = Mob->Mesh->GetSocketRotation(FName("VisionSocket")).Vector();
	const FVector start = Mob->Mesh->GetSocketLocation(FName("VisionSocket"));
	const FVector end = start + (dir * SightConfig.getRadius(Mob->Aggrevated));
	const FName TraceTag("SightTrace");
	FCollisionQueryParams TraceParams(FName("SightParams"), true, Mob);
	TraceParams.TraceTag = TraceTag;
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = true;
	TArray<FHitResult> Hit;
	GetWorld()->DebugDrawTraceTag = TraceTag;
	GetWorld()->SweepMultiByChannel(Hit, start, end, dir.ToOrientationQuat(), ECollisionChannel::ECC_Pawn, FCollisionShape::MakeSphere(SightConfig.CircleRadius), TraceParams);

As you can see I have done a debug draw of this and it looks exactly how I expected it too. The issue occurs when I do a simple loop through Hit. I simply check each object hit with and call GetName() and as long as my player has not moved their is no problems, but as soon as their I move at all, the player name starts getting printed.

EDIT

It appears it was unclear exactly the problem. I need the player to get detected within the trace only, but he is getting detected swept area.

    for (FHitResult hit : Hit) {
//AddOnScreenDebugMessage();
print(hit.GetActor()->GetName());
    }

This begins the moment I start moving:

Thank You,

Hey -

Can you try using the SphereTraceSingle_New() or SphereTraceMulit_New() functions in place of SweepMultiByChannel()? Both of these functions takes an array parameter of actors that will be ignored when the code is ran. If you add your character to that array, it should be omitted from the returned Hit Results.

Cheers

I had not tried this sphere trace, I would be interested to know the difference in performance between the Shape Sweep and SphereTrace (if any). But this does not help because I need the player to be detected when it is within the trace, but he is getting detected at any point on the screen. (athough I have not checked if there is a distance or angle where he is no longer) I shall update this post with pictures to make it clear.

Can you provide a sample project that shows the behavior you’re seeing? I tried to reproduce your issue using the following and the resulting behavior was as expected.

  • Create new class based on Actor

  • Added variable declarations in the header file

    FVector StartLoc;
    FVector EndLoc;
    TArray Hit;
    FQuat rotation;

  • Add sweep call to tick function

    const FName TraceTag(“SightTrace”);
    FCollisionQueryParams TraceParams;
    TraceParams.TraceTag = TraceTag;
    TraceParams.bTraceAsyncScene = true;
    TraceParams.bReturnPhysicalMaterial = true;
    GetWorld()->DebugDrawTraceTag = TraceTag;

     StartLoc = GetActorLocation();
     rotation = GetActorRotation().Quaternion();
     EndLoc = StartLoc + (rotation.GetForwardVector() + 500);
     GetWorld()->SweepMultiByChannel(Hit, StartLoc, EndLoc, rotation, ECollisionChannel::ECC_Pawn, FCollisionShape::MakeSphere(100), TraceParams);
     for(FHitResult OutHit : Hit)
     {
     	if (GEngine) //requires Engine.h include statement
     	{
     		GEngine->AddOnScreenDebugMessage(-1, 4.f, FColor::Magenta, OutHit.GetActor()->GetName());
     	}
     }
    
  • Compile

  • create blueprint of Actor class

  • Add blueprint to level

Following these steps, the actor that was added would only update to show the player in range if the player was within either sphere or the “tunnel” connecting them (see screenshots). Let me know if this information is helpful or if you have other steps that reproduce your behavior.

I used this exact code and it still did not work for me. I am wondering if there is something wrong with my version of UE4 as I am working with the full PhysX API version. I do not know if other problems have come up with this version, but it would seem like it would directly effect this. I am trying to update to the PhysX 3.4, but the link I was using is currently broken.(Got from: A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums) Is there a link to the newer version and the proper way to integrate it?

What exactly what the outcome when you tried? Do you get the same behavior adding the code to a new project? Can you provide your full setup steps / a sample project that shows the behavior you’re seeing?