Created
April 17, 2020 09:22
-
-
Save JoshLmao/723bde5dd4b8c650c116e0d2ada66cce to your computer and use it in GitHub Desktop.
Little guide on how to use UE4's UKismetSystemLibrary::SphereOverlapActors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Kismet\KismetSystemLibrary.h" | |
// Set what actors to seek out from it's collision channel | |
TArray<TEnumAsByte<EObjectTypeQuery>> traceObjectTypes; | |
traceObjectTypes.Add(UEngineTypes::ConvertToObjectType(ECollisionChannel::ECC_Pawn)); | |
// Ignore any specific actors | |
TArray<AActor*> ignoreActors; | |
// Ignore self or remove this line to not ignore any | |
ignoreActors.Init(this, 1); | |
// Array of actors that are inside the radius of the sphere | |
TArray<AActor*> outActors; | |
// Total radius of the sphere | |
float radius = 750.0f; | |
// Sphere's spawn loccation within the world | |
FVector sphereSpawnLocation = GetActorLocation(); | |
// Class that the sphere should hit against and include in the outActors array (Can be null) | |
UClass* seekClass = AEnemyBase::StaticClass(); // NULL; | |
UKismetSystemLibrary::SphereOverlapActors(GetWorld(), sphereSpawnLocation, radius, traceObjectTypes, seekClass, ignoreActors, outActors); | |
// Optional: Use to have a visual representation of the SphereOverlapActors | |
// DrawDebugSphere(GetWorld(), GetActorLocation(), radius, 12, FColor::Red, true, 10.0f); | |
// Finally iterate over the outActor array | |
for (AActor* overlappedActor : outActors) { | |
UE_LOG(LogTemp, Log, TEXT("OverlappedActor: %s"), *overlappedActor->GetName()); | |
} |
God bless your soul.
line 5 is a lifesaver thanks.
Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks man, it's really helpful!