I am creating several InstancedStaticMeshes at runtime like this:
for (const auto& StaticMesh : StaticMeshes)
{
UInstancedStaticMeshComponent* StaticMeshComponent = NewObject<UInstancedStaticMeshComponent>(this);
StaticMeshComponent->SetStaticMesh(StaticMesh);
StaticMeshComponent->SetMobility(EComponentMobility::Static);
StaticMeshComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);
StaticMeshComponent->RegisterComponent();
StaticMeshComponent->AttachTo(DefaultRoot);
// Add to array
InstancedStaticMeshComponents.Add(StaticMeshComponent);
}
And later use them to create instances like this:
// Pick a random mesh
const int32 Num = InstancedStaticMeshComponents.Num();
if (Num == 0)
{
return;
}
UInstancedStaticMeshComponent* InstancedStaticMeshComponent = InstancedStaticMeshComponents[FMath::RandRange(0, Num - 1)];
if (InstancedStaticMeshComponent == nullptr)
{
return;
}
// Calculate a transform
FTransform Transform = SocketedMeshComponent->GetSocketTransform(SocketName);
// Create the mesh
InstancedStaticMeshComponent->AddInstanceWorldSpace(Transform);
When I do this, I get the following warning:
Warning Mobility of BP_InstanceMaker_C_1411 : Root Component has to be ‘Movable’ if you’d like to Mobility of {0} : {1} has to be ‘Movable’ if you’d like to {2}. .
The root scene component of the Actor these components are on is set to static, as well as each UInstancedStaticMeshComponent I create. It’s a strange error, because it looks like it should be parameterized (not the {0}, {1} and {2}) but isn’t. Any ideas?