x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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: alt text

Thank You,

Product Version: UE 4.13
Tags:
more ▼

asked Nov 02 '16 at 04:32 PM in C++ Programming

avatar image

joelComberiati
112 26 22 28

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hey JoelComberiati-

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

Doug Wilson

more ▼

answered Nov 02 '16 at 05:45 PM

avatar image joelComberiati Nov 02 '16 at 07:48 PM

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.

avatar image Doug E ♦♦ STAFF Nov 04 '16 at 05:19 PM

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.

alt text alt text

insweep.png (819.6 kB)
outsweep.png (721.2 kB)
avatar image joelComberiati Nov 05 '16 at 08:09 AM

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: https://wiki.unrealengine.com/PhysX,_Integrating_PhysX_Code_into_Your_Project#Compiling_the_PhysX_Source_Code) Is there a link to the newer version and the proper way to integrate it?

avatar image Doug E ♦♦ STAFF Nov 07 '16 at 03:59 PM

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?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question