I have an Actor class that is creating UStaticMeshComponents based on an int value modified in editor. When the value is changed in editor, the StaticMeshComponents are created correctly, however, the components do not show up in editor as editable. What am I doing wrong?
void AComboPuzzle::OnConstruction(const FTransform & Transform)
{
//Empty the array and delete all it's components
for (auto It = SMArray.CreateIterator(); It; It++)
{
(*It)->DestroyComponent();
}
SMArray.Empty();
//Register all the components
RegisterAllComponents();
//The base name for all our components
FName InitialName = FName("MyCompName");
for (int32 i = 0; i < NumToSpawn; i++)
{
//Create a new Component
//The first parameter is the "parent" of the our new component
UStaticMeshComponent* NewComp = NewObject<UStaticMeshComponent>(this, InitialName);
//Add a reference to our array
SMArray.Add(NewComp);
//Change the name for the next possible item
FString Str = "MyCompName" + FString::FromInt(i + 1);
//Convert the FString to FName
InitialName = (*Str);
//If the component is valid, set it's static mesh, relative location and attach it to our parent
if (NewComp)
{
GLog->Log("Registering comp...");
//Register the new component
NewComp->RegisterComponent();
//Set the static mesh of our component
NewComp->SetStaticMesh(SM->GetStaticMesh());
//Set a random location based on the values we enter through the editor
FVector Location;
//Set the random seed in case we need to change our random values
FMath::SRandInit(RandomSeed);
Location.X += FMath::RandRange(-FMath::Abs(XThreshold), FMath::Abs(XThreshold));
Location.Y += FMath::RandRange(-FMath::Abs(YThreshold), FMath::Abs(YThreshold));
NewComp->SetWorldLocation(Location);
//Attach the component to the root component
NewComp->AttachToComponent(GetRootComponent(), FAttachmentTransformRules::KeepRelativeTransform, NAME_None);
}
}
}