Hello,
i have a function called OnOverlapBegin, which is executed when my collision box is triggered. I want to access the static mesh component of the overlapped actor , how can I do that?
Thanks in advance.
Hello,
i have a function called OnOverlapBegin, which is executed when my collision box is triggered. I want to access the static mesh component of the overlapped actor , how can I do that?
Thanks in advance.
AMyTriggerBox.h
UCLASS()
class CONTENTEXAMPLESCPP_API AMyTriggerBox : public ATriggerBox
{
GENERATED_BODY()
public:
AMyTriggerBox();
virtual void BeginPlay() override;
UFUNCTION()
void OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
};
AMyTriggerBox.cpp
void AMyTriggerBox::BeginPlay()
{
Super::BeginPlay();
GetCollisionComponent()->OnComponentBeginOverlap.AddDynamic(this, &AMyTriggerBox::OnOverlapBegin);
}
void AMyTriggerBox::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (OtherActor && OtherActor != this && OtherComp)
{
TArray<UStaticMeshComponent*> MeshComponents;
OtherActor->GetComponents<UStaticMeshComponent>(MeshComponents);
for (UStaticMeshComponent* MeshComponent : MeshComponents)
{
UE_LOG(LogTemp, Warning, TEXT("%s"), *MeshComponent->GetName())
}
}
}
This doesnt work, for example if i have an actor with:
a camera component, a static mesh and a collider, for one reason i get wrong names, and also i get two names… the names are StaticMeshComponents_0/1 . Why i cant have their names?