CoreBlueprintFunctionLibrary.h
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "CoreBlueprintFunctionLibrary.generated.h"
UCLASS()
class YOURGAME_API UCoreBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
UFUNCTION(BlueprintCallable)
static FString GetCollisionName(UPrimitiveComponent* OtherComp, FHitResult HitResult);
};
CoreBlueprintFunctionLibrary.cpp
#include "CoreBlueprintFunctionLibrary.h"
#include "Engine/HitResult.h"
#include "PhysicsEngine/BodySetup.h"
FString UCoreBlueprintFunctionLibrary::GetCollisionName(UPrimitiveComponent* OtherComp, FHitResult HitResult)
{
if (HitResult.ElementIndex == -1) HitResult.ElementIndex = 0;
FString foundName = "";
if (OtherComp != nullptr && HitResult.ElementIndex > -1)
{
if (UStaticMeshComponent* mesh = Cast<UStaticMeshComponent>(OtherComp))
{
FKShapeElem* el = mesh->GetStaticMesh()->GetBodySetup()->AggGeom.GetElement(HitResult.ElementIndex);
GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Cyan, *el->GetName().ToString());
foundName = el->GetName().ToString();
}
else if (UStaticMesh* mesh2 = Cast<UStaticMesh>(OtherComp))
{
FKShapeElem* el = mesh2->GetBodySetup()->AggGeom.GetElement(HitResult.ElementIndex);
GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Cyan, *el->GetName().ToString());
foundName = el->GetName().ToString();
}
}
return foundName;
}