New StaticMeshComponent is created dynamically during the game.
For the Server, everything works perfectly.
However, for the Client, everything replicates (scale, location, rotation) excluding the material.
If I change to
StaticMeshComponent->GetStaticMesh()->SetMaterial(MaterialId, MaterialInstance);
The material is setting and replicates for all Static Meshes on the level
How I can set material for a StaticMeshComponent to have it on the Client as well?
It’s not clear for me why just material is not replicated.
UStaticMeshComponent* StaticMeshComponent = NewObject<UStaticMeshComponent>(this);
if (!StaticMeshComponent) { return; }
StaticMeshComponent->RegisterComponent();
StaticMeshComponent->SetStaticMesh(BuldingMesh.GetMesh());
StaticMeshComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
StaticMeshComponent->SetRelativeTransform(BuldingMesh.GetShapeTranform());
UMaterialInstanceDynamic * MaterialInstance = StaticMeshComponent->CreateDynamicMaterialInstance(0, BuldingMesh.GetMaterial());
if (MaterialInstance)
{
StaticMeshComponent->SetMaterial(MaterialId, MaterialInstance);
//StaticMeshComponent->GetStaticMesh()->SetMaterial(MaterialId, MaterialInstance);
}
StaticMeshComponent->SetIsReplicated(true);