After importing a bunch of static meshes. How would I add all of these to an actor in the editor. I can build things in the constructor but my staticmeshes only appear on import.
I am looking to have this type of relationship. Actor<-(Dynamically made SceneComponent)<-(Several Static Meshes)
I have been unable to do this in the constructor since I won’t know what meshes to load until the GLTF import is done and the static meshes are created. Here is what I have:
TArray<UStaticMesh*> CreateComponent(TArray<UStaticMesh*> meshArray)
{
//Copy the Mesh Array and get the number of elements for the for loop.
TArray<UStaticMesh*> result = meshArray;
int arrayCount = meshArray.Num();
//Make new Actor, Get that world, create a scene component to this world.
AHActor* testObject = NewObject<AHActor>();
UWorld* World = testObject->GetWorld();
USceneComponent* SceneComponent = NewObject<USceneComponent>(World, "MyTestComp");
SceneComponent->RegisterComponentWithWorld(World);
//Attach the new SceneComponent to the root node and then start the for loop for the meshes.
for (int i = 0; i < arrayCount; i++)
{
//Get the array element name to name the staticmeshcomponont. Error check if just in case. Attach the mesh to the component then attach mesh comp to scene comp.
FName YourMeshName(meshArray[i]->GetFName());
UStaticMeshComponent* NewComp = NewObject<UStaticMeshComponent>(UStaticMeshComponent::StaticClass(), YourMeshName);
if (!NewComp)
{
return result;
}
NewComp->SetStaticMesh(meshArray[i]);
NewComp->AttachToComponent(SceneComponent, FAttachmentTransformRules::KeepRelativeTransform);
}
return result;
}