Overlap check on the geometry of an actor instead of against the world for optimization.

Hi, I have been looking for a way to do overlap checks against the geometry of an actors. But as far as I know, there only exists overlap checks that trace against the world. While this does what I want it to, it seems like there is a lot of wasted performance when we keep checking against the world instead of the actor we are interested in.

Currently I have this code to return a boolean based on if a box is overlapping with anything in the world:

return FPhysicsInterface::GeomOverlapBlockingTest(
		World,
		FNavMeshStatic::CollisionBoxes[LayerIdx],
		GetGlobalLocation(ChunkLocation).ToVector() + 
           FNavMeshStatic::NodeHalveSizes[LayerIdx],
		FQuat::Identity,
		ECollisionChannel::ECC_WorldStatic,
		FCollisionQueryParams::DefaultQueryParam,
		FCollisionResponseParams::DefaultResponseParam
	);

This method was used inside the ::OverlapAnyTestByChannel method in WorldCollision.cpp.

But in my specific use-case, I have access to the actors I would like to do these overlap checks against. So for example, I have a basic box shape, and would like to know if this shape is overlapping with the geometry of a certain actor.

This is for a custom navigation-mesh I am developing, and I have a list of all the actors I’m interested in for generating this navmesh. Doing overlap check against the world every time seems like a waste of performance when I know exactly what actors I should be checking against.

Edit:
I’ve found this method in the PhysInterface_Chaos.h

static ENGINE_API bool Overlap_Geom(const FBodyInstance* InBodyInstance, const FCollisionShape& InCollisionShape, const FQuat& InShapeRotation, const FTransform& InShapeTransform, FMTDResult* OutOptResult = nullptr, bool bTraceComplex = false);

Is has a comment declaring that it is ‘a trace function for testing specific geometry (not against a world)’. I will check it out and see if this is what I am looking for.

Hey! You could use object channels, found in the project settings:

After that, in your actor, you can set this channel:

image

This could explain some more:

This is not what I was looking for, I’m sorry if my question was a bit vague.
I don’t need a custom collision channel which can be set on an actor, but rather if one specific shape ( like a box ) is overlapping a given actor.
Ofcourse without doing a check against the whole world, but just the shape against only one actor.

I could check the source code for the collision components instead of actors, maybe they have the methods I am looking for. Otherwise I will need to build my own overlap check based on the actual geometry of the actor.

Normally a simple world-overlap check is enough, and the generation/updating of my custom navmesh is already extremely performant. But the world-overlap check is by far taking the most time, and is logical if you think about it. Every single check is against the whole world instead of just the actor you are interested in.

It seems that ‘FPhysInterface_Chaos::Overlap_Geom’ is a method that acomplishes this.

Some sample code that returns a boolean based on if a collision-box is overlapping with the geometry of an actor:

TArray<UPrimitiveComponent*> PrimitiveComponents;
Actor->GetComponents<UPrimitiveComponent>(PrimitiveComponents);
for (const UPrimitiveComponent* PrimitiveComponent : PrimitiveComponents)
{
		if (!PrimitiveComponent || !PrimitiveComponent->IsCollisionEnabled()) continue;
		if(FPhysInterface_Chaos::Overlap_Geom(PrimitiveComponent->GetBodyInstance(), /* collision-shape */, /* rotation collision-shape */, FTransform(/* rotation actor */, /* location actor */))) return true;
}
return false;
1 Like

For anyone wanting a BP approach, there is a bunch of nodes that single it out:

Same goes for tracing and volume tracing. Handy if you know what you want upfront and do not want to faff about with channel / object types.

While this is a solitution to check for overlaps between a box and an actors collision component, the c++ behind this node will still do a trace against the world instead of the actual geometry of this one component. But extreme optimizations shouldn’t be done in BP anyway.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.