On Begin play I add about or greater 200 x 200 instances like this with my FPS clocking to 120 fps :
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
FVector newLocation = CompOrigin + FVector(i*OffsetX, j*OffsetY, k*OffsetZ);
Positions.Add(newLocation);
HISMC->AddInstance(FTransform(newLocation));
}
}
I try to update the position of these meshes at runtime using parallel for loop in a similar spirit of runtime mesh component example here https://github.com/Koderz/RuntimeMes…tedTerrain.cpp .
Rather than use tick for this actor I call a member function thusly :
// Call RepeatingFunction once per .05 second, starting five seconds from now.
GetWorldTimerManager().SetTimer(MemberTimerHandle, this, &AHISMActor::RepeatingFunction, 0.05f, true, 5.0f);
In that member function I simply try to update positions of already created instanced meshes like this :
ParallelFor(someN *someN , &SomeComp, &somePositions, someScale, someAnimOffsetX, someAnimOffsetY, someN, someHeightSensitivity](int32 Index)
{
int32 XIndex = Index % someN;
int32 YIndex = Index / someN;
float HeightScale = FMath::Cos((XIndex * someScale) + someAnimOffsetX) + FMath::Sin((YIndex * someScale) + someAnimOffsetY);
somePositions[Index].Z += HeightScale * someHeightSensitivity;
SomeComp->UpdateInstanceTransform(Index, FTransform(somePositions[Index]), false,false, true);
}, true);
First the parallel for loop cannot be used hence I witness tremendous drop in frame rate when I try to update instances. It only works with single thread that you have to force otherwise you get plenty of runtime errors including MallocTBB and Emplace error in ArrayList. I wonder what is a nice way to update huge number of meshes, I don’t care about collisions or physics, just want to simulate some movement of already rendered meshes. Please advise.