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