Download

Getting Overlapping actors of a sphere component attached to mesh on character class?

I am looking to either trace a sphere or get the overlapping actors of a subcomponent sphere on a character class in order to create a melee combat system.

Have had no luck with either approach, anyone have an example of this?

this didnt do anything…

construct:
HitSphere = CreateDefaultSubobject<USphereComponent>(TEXT(“SphereHit”));
HitSphere->AttachTo(GetMesh());
HitSphere->bGenerateOverlapEvents = true;
HitSphere->OnComponentBeginOverlap.AddDynamic(this, &ABearGameCharacter::OnHitSphereOverlapBegin);

function

void ABearGameCharacter::OnHitSphereOverlapBegin(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
Jump();
}

K finally figured it out, worked with a trace like this:

FCollisionQueryParams FCQP = FCollisionQueryParams(FName(TEXT("RV_Trace")), true, this);
FCQP.bTraceComplex = true;
FCQP.bTraceAsyncScene = false;
FCQP.bReturnPhysicalMaterial = false;
FCQP.AddIgnoredActor(BearPawn);

    //Needs at least one unit of movement, guessing it sweeps to get the actors
FVector Start = BearPawn-&gt;GetActorLocation() + BearPawn-&gt;GetActorForwardVector() * 26; //This class works like a weapon so BearPawn is the owning pawn
FVector End = Start + BearPawn-&gt;GetActorForwardVector() * 1;

FCollisionResponseParams FCRP = FCollisionResponseParams(ECR_Overlap);
TArray&lt;FHitResult&gt; Hits;
GetWorld()-&gt;SweepMultiByChannel(Hits, Start, End, FQuat(), ECC_Pawn, FCollisionShape::MakeSphere(10), FCQP, FCRP);

if(Hits.Num() &gt; 0)
{
	for(int i = 0; i &lt; Hits.Num(); i++)
	{
		//Do What you need to all the overlapping actors
	}
}