TArray meshReferences;
meshReferences.Add(“StaticMesh’/Game/StarterContent/Shapes/Shape_NarrowCapsule.Shape_NarrowCapsule’”);
meshReferences.Add(“StaticMesh’/Game/StarterContent/Shapes/Shape_QuadPyramid.Shape_QuadPyramid’”);
meshReferences.Add(“StaticMesh’/Game/StarterContent/Shapes/Shape_Cylinder.Shape_Cylinder’”);
meshReferences.Add(“StaticMesh’/Game/StarterContent/Shapes/Shape_Wedge_A.Shape_Wedge_A’”);
int32 randomMesh = rand() % meshReferences.Num();
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false;
this->bReplicates = true;
this->bReplicateMovement = true;
FString meshToSpawn = meshReferences[randomMesh];
//Setup Mesh
static ConstructorHelpers::FObjectFinder<UStaticMesh> staticMesh(*meshToSpawn);
mesh = staticMesh.Object;
meshComp = CreateDefaultSubobject < UStaticMeshComponent >(TEXT("mainComp"));
meshComp->SetStaticMesh(mesh);
//Set Mesh Material
static ConstructorHelpers::FObjectFinder<UMaterial> Material(TEXT("Material'/Game/StarterContent/Materials/M_CobbleStone_Rough.M_CobbleStone_Rough'"));
meshComp->SetMaterial(0, Material.Object);
UStaticUtilityFunctions::SetupSMComponentsWithCollision(meshComp);
//meshComp->AttachParent = this->RootComponent;
this->SetRootComponent(meshComp);
With this code I try to get every instance of this class a random mesh. Currently I wanted to test it just with the StarterContent Shapes. In the final result it should spawn buildings of the same type, that don’t look exactly the same.
But when I compile and spawn 10x10 instances, all look the same, although the mesh-reference correctly picks random mesh-references and passes them as the parameter for FObjectFinder…
What am I missing?