Hej, I've been trying to click on StaticMeshComponent during Run-time, but not able to click on particular StaticMeshComponent. I've tried the below logic to click and set the material inside OnClick() Function, but not able succeed. Is AddDynamic approach correct ??
In .cpp
StaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMeshComponentCOMP"));
ConstructorHelpers::FObjectFinder<UStaticMesh> StaticMesh_obj(TEXT("/Game/StarterContent/Meshs/Chairs_Chair1"));
StaticMeshComponent->SetStaticMesh(StaticMesh_obj.Object);
StaticMeshComponent->OnClicked.AddDynamic(this, &AMyActor::OnClick);
StaticMeshComponent->AttachTo(RootComponent);
// OnClick Function
void AMyActor::OnClick(UPrimitiveComponent* pComponent)
{
ConstructorHelpers::FObjectFinder<UMaterial> MeshMaterial(TEXT("/Game/GTFreeMaterials/Materials/Metal_BrushedSteel"));
// Set properties for Staic mesh component
StaticMeshComponentArray[i]->SetMaterial(0, MeshMaterial.Object);
FMessageDialog::Open(EAppMsgType::Ok, FText::FromString(TEXT("Clicked")));
}
In .h
void OnClick(UPrimitiveComponent* pComponent);
Could you guys please help me in this issues Or guide me any another efficient logic to solve my problem.
P.S: Game Mode : Mouse Click mode