C++/Blueprint - Find all overlapping colliders in specific point

I’m looking for a function - other than iterating over all actors in scene - to find all overlapping colliders in some specific point. Reason why I’m looking for this is because I’m writing my own movement physics for character (since CharacterMovementComponent is too gigantic and too hard to understand in a short time) and I want a function to check if it is standing on a floor or other proper collider. For now I’m just using normal physics, so I don’t even have to check it, but in a long way I would want to perform some more complex operations.

Ok, so I figured out how to do it. We have many functions to check for collisions (for example from UKismetSystemLibrary), but in my opinion the best one is the simple LineTraceSingleByObjectType (or similar) from UWorld class. My simple method to check for collisions:

float AMyCharacter::CheckCollision(FVector InVec, float D) {
	if (D <= 0)return -1;
	FVector TraceStart = GetActorLocation();
	FVector TraceEnd = TraceStart + InVec*D;
	FHitResult OutHit;
	GetWorld()->LineTraceSingleByObjectType(OutHit, TraceStart, TraceEnd, 
           FCollisionObjectQueryParams(
                    ECC_TO_BITFIELD(ECC_WorldStatic) | ECC_TO_BITFIELD(ECC_WorldDynamic)
           ), FCollisionQueryParams(TEXT("IKTrace"), true, this));
	if (OutHit.bBlockingHit) return OutHit.Distance;
	else return -1;
}

Now I saw that my question was about ALL overlapping bodies. The changes we need to do is to use LineTraceMultiByObjectType, not LineTraceSingle, and pass an array of FHitResult instead of single FHitResult. But without that the answer is the same.


One note to this complex ECC_TO_BITFIELD macro - apparently Unreal Engine takes flags for colliders as bit flags, for example - if we have various generic colliders types, as WorldStatic, WorldDynamic, PhysicsBody, BlockAll etc, we can pass information for which types we have to check as simple int32 variable: 11100010 00000000. Here we will get info that we check for first three types and the seventh one, rest are avoided. The ECC_TO_BITFIELD is just a macro which changes enum type (collider nr 1, collider nr 2… and so on) into series of bits with 1 on one specific place and zeroes everywhere else. The | operator is boolean OR operator, which for every pair of bits gives 1 if any of input bits were 1 and gives 0 otherwise. It took me a moment to figure that out, so that’s why I write this appendix :slight_smile: