(Oops, made it a topic instead of a question)
After refactoring a bit of code to work with a few global Instanced Static Mesh Components instead of spawning/destroying static mesh components, i’ve run into an issue.
I can’t see my mesh instances!
Their collision is there, they’re in the Instances array and they’re being updated properly (I call UpdateInstance on them every frame to move them around), I can see them with Visibility Collision and Player Collision in the editor, but in game view, I cannot see them. Here’s how I add the Instanced mesh components (in BeginPlay):
InstancedItemMeshes.Reserve(Resources.Num());
for (const FResourceInfo& Res : Resources)
{
UInstancedStaticMeshComponent* Comp = Cast<UInstancedStaticMeshComponent>(AddComponentByClass(UInstancedStaticMeshComponent::StaticClass(), false, FTransform(), false));
Comp->SetMobility(EComponentMobility::Movable);
Comp->AttachToComponent(GetRootComponent(), FAttachmentTransformRules::SnapToTargetNotIncludingScale);
Comp->SetStaticMesh(Res.BeltMesh);
Comp->SetMaterial(0, Res.BeltMesh->GetMaterial(0));
InstancedItemMeshes.Add(Comp);
}
Here, Res is a custom struct that holds some information I need.
And here’s how I add the instances:
IT.MeshInstanceId = IT.GetMeshComponent(GameState)->AddInstance(FTransform(), true);
And finally, here’s how I update them:
MeshComp->UpdateInstanceTransform(Item.MeshInstanceId, FTransform(NewWorldRot, NewWorldPos), true, true, true);
MeshComp->MarkRenderStateDirty();
Here Item is also a custom struct that holds some information relevant to the system this is apart of.
(See my previous post about this project for some more context, if needed.)