I am new to Unreal Engine and gamedev, so I could be wrong at any of my suggestions, so please correct me about anything.
Context: I am developing clone of Minecraft but with cubic chunks. I want chunks to be an Actors so they can posses array of blocks, which I think I should make Components.
Below, when I say “update” I mean “destroy and spawn”.
When Player moves from one chunk to another, huge amount of chunks need to be destroyed and same amount need to be spawned. I don’t think I could use pooling because in the future development chunks will have an array of blocks, which i will have to update anyway. I want chunks to update not all at once, but as much game can update per Tick, so I thought of updating chunks in separate thread and for that I’ve researched UE Tasks System, but it seems I can’t spawn nor destroy actors in any thread except Game Thread.
I’ve designed a system of two queues (destroy and spawn), so game can update not all chunk in single Tick and leave some for another:
void AMainGameStateBase::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
// location of chunk in chunks coordinate system
FIntVector ChunkLocation;
if(DestroyChunksQueue.Dequeue(ChunkLocation))
DestroyChunk(ChunkLocation);
else if (SpawnChunksQueue.Dequeue(ChunkLocation))
SpawnChunk(ChunkLocation);
}
And it works mostly as I expected, but chunks update too slow, so I thought of updating them more than once per Tick:
for(int i = 0; i < 50; i++)
{
FIntVector ChunkLocation;
if(DestroyChunksQueue.Dequeue(ChunkLocation))
DestroyChunk(ChunkLocation);
else if (SpawnChunksQueue.Dequeue(ChunkLocation))
SpawnChunk(ChunkLocation);
else
break;
}
But it feels like hard coding, the speed of update is fps related and it never checks if it causes any performance lack, so I think I’m doing something wrong or just missing something.
Any thoughts and comments on my problem would be great.