Hi all Is there a way to declare a StaticMesh in a class and that set the UPROPERTY() in the way that I can set shapes such as cube cone etc. in editor just like with primitive types such as int, float ? Or do I have to use object finder to load the static mesh ?
Here is a quick psuedo code:
// Header file (.h):
UPROPERTY(EditAnywhere, Category = "Your Category Name")
UStaticMesh* MyMesh
UPROPERTY()
UStaticMeshComponent* MyMeshComponent;
virtual void OnConstruction(const FTransform& Transform) override;
// Source file (.cpp):
MyMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MyMeshComponent"));
MyMeshComponent->SetupAttachment(RootComponent);
void OnConstruction(const FTransform& Transform)
{
Super::OnConstruction( Transform);
MyMeshComponent->SetStaticMesh(nullptr);
if (MyMesh != nullptr)
{
MyMeshComponent->SetStaticMesh(MyMesh);
}
}
Right my code is very similar except that I store pointers in array, I know why it wasn’t working I have UStaticMesh wrapped up in TSubClassOf<> that’s why I couldn’t set the static mesh thanks a lot !