My goal is to create my C++ classes and create the classes components, etc in the C++ class, then derive a blueprint from those C++ classes and in that blueprint assign assets (static meshes, skeletal meshes, materials, etc). My ideal workflow would be to allow the blueprint to act as the selector of assets, while the C++ does the heavy work, as I much prefer to work in C++ over blueprints for logic.
Right now that’s not working out very well, however,
Current version of the class with unrelated parts removed:
UCLASS()
class HEXINSTANTIATION_API AInstanceCreator : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AInstanceCreator(const FObjectInitializer& ObjectInitializer);
public:
// UInstancedStaticMeshComponents
UInstancedStaticMeshComponent* InstancedMesh1;
UInstancedStaticMeshComponent* InstancedMesh2;
UInstancedStaticMeshComponent* InstancedMesh3;
public:
// Static Mesh that we want to use for our UInstancedStaticMeshComponent
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Instantiatables)
UStaticMesh* Mesh1;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Instantiatables)
UStaticMesh* Mesh2;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Instantiatables)
UStaticMesh* Mesh3;
};
Then in the .cpp file:
// Sets default values for this actor's properties
AInstanceCreator::AInstanceCreator(const FObjectInitializer& ObjectInitializer)
{
PrimaryActorTick.bCanEverTick = false;
InstancedMesh1 = ObjectInitializer.CreateDefaultSubobject<UInstancedStaticMeshComponent>(this, TEXT("Instanced Mesh 1"));
InstancedMesh2 = ObjectInitializer.CreateDefaultSubobject<UInstancedStaticMeshComponent>(this, TEXT("Instanced Mesh 2"));
InstancedMesh3 = ObjectInitializer.CreateDefaultSubobject<UInstancedStaticMeshComponent>(this, TEXT("Instanced Mesh 3"));
RootComponent = InstancedMesh1;
InstancedMesh2->AttachParent = RootComponent;
InstancedMesh3->AttachParent = RootComponent;
InstancedMesh1->SetStaticMesh(Mesh1);
InstancedMesh2->SetStaticMesh(Mesh2);
InstancedMesh3->SetStaticMesh(Mesh3);
}
My feeling is that because I haven’t set the Mesh in the constructor, the assignment is meaningless and then the constructor never gets visited again later, so where should I put the InstancedMesh1->SetStaticMesh(Mesh1); code so that it picks up when I add/change a Mesh in a blueprint? (If it’s important, I also want to use the OnConstruction function in C++, so i need the solution to work cooperatively with that function, I don’t think setting the initialization in OnConstruction would be the appropriate workflow, since I don’t always want to use OnConstructed, please correct me if I’m wrong, though.)
Thanks you for the time and assistance.