How do I get the amount of overlapping geometry between two meshes?

The specific application is for advanced, accurate damage calculation for AoE effects. My game will have playable characters of different sizes, so I want to be able to measure how much of a characters mesh is within an AoE volume.

Since the AoE volumes won’t always be a sphere (occasionally a cube/rectangle, cone, or cylinder) and the character models won’t ever be any simple shape, I wanted to know if there’s any in-engine way to get the amount of overlapping geometry between two meshes.

I have workarounds planned in case no such premade method or procedure exists, such as adding detection points as components at set spaces and getting a rough estimate by counting them during overlap, but I would much rather know if there’s a way to access both meshes’ respective geometry data and calculate any measure of the overlap between them (volume, surface area, anything using the actual mesh geometry).

I am not aware of any built in engine solution for this, however I believe you can save a lot of performance by checking a few select points when you need, rather than adding new components that will cause additional collision calculations all the time.

PrimitiveComponent provides the following function which can be helpful in this case :

/**
* Returns the distance and closest point to the collision surface.
* Component must have simple collision to be queried for closest point.
*
* @param Point				World 3D vector
* @param OutPointOnBody		Point on the surface of collision closest to Point
* @param BoneName			If a SkeletalMeshComponent, name of body to set center of mass of. 'None' indicates root body.
*
* @return		Success if returns > 0.f, if returns 0.f, it is either not convex or inside of the point
*				If returns < 0.f, this primitive does not have collsion
*/
UFUNCTION(BlueprintCallable, Category = "Collision", meta=(UnsafeDuringActorConstruction="true"))
float GetClosestPointOnCollision(const FVector& Point, FVector& OutPointOnBody, FName BoneName = NAME_None) const;

I am not sure myself what the BoneName parameter really does, but ignoring that you can use this to check if a selection of bones/sockets on your character are overlapping the collision primitive or not.

Here is a quick blueprint prototype :

I’m using a sphere collision component, but should work with any primitive component.

Note that I didn’t bother selecting specific sockets and used all of them, mannequin has like 70 sockets, but it’s good enough for prototyping.

In your case I suggest you predefine an array of relevant sockets to check (add some in the skeleton if necessary).

1 Like

Thanks for the response. Some of what you’ve suggested here are the workarounds I mentioned, but you did provide some useful information. It slipped my mind that any components would need some collision geometry to be detected in overlaps, so that wouldn’t be a really good way to handle it. However, testing for overlapping bones, or more specifically overlapping sockets, would be a good (if less accurate) option.

The characters are being designed to be extremely modular, extremely customizable, and will have one or more sockets for armor pieces per body part. Perhaps using sockets in bone sets and a little math can give me fairly accurate estimations. E.g., if say “Forearm_Left_ForwardEndSocket” reads as overlapped, but the others on the arm don’t, and I know the size of the AoE sphere and its origin, I can calculate the distance between it’s edge and the other sockets on the arm to get a close approximation of how much of the arm is covered, though that may be a bit over-kill.

If there’s no direct way to test overlap geometry percentage or volume, then just checking for bone overlap or body-segment overlap will be sufficient. But for now I’ll wait a bit longer to see if anyone knows of a way to actually find the overlap amount. It’ll be a while yet before I get to the point that I need a working method.