How to get collision primitive name involved in collision?

I have few collision primitives assigned to my static mesh.
Each collision primitve has a ‘name’ property (static mesh details->collision->primitives->boxes->0->name)

During ‘Event Hit’ I would like to get a name of primitive that was involved in this collision.
Is this possible?
May be done in Blueprints od C++.

ACustomActor can be whatever actor that is testing or you could push the function into a blueprint library if needed.

Then just hook up the overlap or hit other component to the function and pass in the index if present and you will get the collision primitives name

header file

UFUNCTION(BlueprintCallable)
FString GetCollisionName(UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

cpp

FString ACustomActor::GetCollisionName(UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
	if (OtherBodyIndex == -1) OtherBodyIndex = 0;

	FString foundName = "";
	if (OtherComp != nullptr && OtherBodyIndex > -1) 
	{
		
		if (UStaticMeshComponent* mesh = Cast<UStaticMeshComponent>(OtherComp))
		{
			FKShapeElem* el = mesh->GetStaticMesh()->GetBodySetup()->AggGeom.GetElement(OtherBodyIndex);
			foundName = el->GetName().ToString();
		}

		else if (UStaticMesh* mesh2 = Cast<UStaticMesh>(OtherComp))
		{
			FKShapeElem* el = mesh2->GetBodySetup()->AggGeom.GetElement(OtherBodyIndex);
			foundName = el->GetName().ToString();
		}
	}

	return foundName;
}

Works with overlaps and collisions.

You will need to include

#include "PhysicsEngine/BodySetup.h"
in the cpp file

Example box collider with name “My BOX”


In Game

and bp

2 Likes