I have a system where I am reading an fbx object in a folder, constructing a procedural mesh objects from that data and then optionally it can be used to build a static mesh. This all works fine.
My problem is that when replicating to a client, objects spawned WHILE the client is in the session are being wiped. This only happens for replicated objects that are spawned after the client has joined the session-- objects spawned before they join are fine.
I am assuming this is because to produce the procedural mesh, I need to make it transient, but I think unreal is garbage collecting it or something like that. I could be off on this though as my understanding of how unreal replicates transient data is pretty limited and I can’t really find any information on the subject.
When I debug, the procedural mesh is being generated and shows for a split second on the client side (valid) before returning as invalid a fraction of a second later. The object itself is still valid and present, but the mesh is gone. This happens even if I create/set a static mesh from the procedural mesh, or assign it to a constant procedural mesh variable.
Would super appreciate feedback!
Here’s the code for that function:
void URuntimeStaticMeshImporterBFL::CreatePMCFromData(FSTMIObjectData FbxData, UProceduralMeshComponent*& OutMesh)
{
if (FbxData.bGotMeshData)
{
if (!FbxData.MeshData.IsEmpty())
{
int32 RandomInt{};
RandomInt = UKismetMathLibrary::RandomIntegerInRange(0, 999);
FString intstring = FString::FromInt(RandomInt);
FString procname = FString("RSMI_ProcMesh") + intstring;
UProceduralMeshComponent* procmesh = NewObject<UProceduralMeshComponent>(GetTransientPackage(), FName(procname), EObjectFlags::RF_Transient);
FString nummeshdata = FString::FromInt(FbxData.MeshData.Num());
for (int8 i = 0; i < FbxData.MeshData.Num(); i++)
{
FString currentindex = FString::FromInt(i);
procmesh->CreateMeshSection_LinearColor(
i,
FbxData.MeshData[i].Vertices,
FbxData.MeshData[i].Triangles,
FbxData.MeshData[i].Normals,
FbxData.MeshData[i].UV0,
FbxData.MeshData[i].VertexColors,
FbxData.MeshData[i].Tangents,
true
);
}
OutMesh = procmesh;
}
else
{
UE_LOG(LogTemp, Warning, TEXT("RuntimeStaticMeshImporter -> CreateProceduralMeshFromData -> FbxData.MeshData is empty!"));
return;
}
}
else
{
UE_LOG(LogTemp, Warning, TEXT("RuntimeStaticMeshImporter -> CreateProceduralMeshFromData -> FbxData is invalid!"));
}
return;
}