# Spawn/Destroy exact amount of Actors per Tick to not cause any performance lack

**URL:** <https://forums.unrealengine.com/t/spawn-destroy-exact-amount-of-actors-per-tick-to-not-cause-any-performance-lack/2131052>\
**Category:** Programming & Scripting\
**Tags:** c-c, c-class-wizard, c-and-bluepri, c-custommeshcomponen, c-and-blueprint, c-error, destroying-actors, c-class, c-custom-shape, c-programming, c-cone-shape, unreal-engine, spawning-actors, question, CPP\
**Created:** [November 17, 2024, 3:02pm UTC](https://forums.unrealengine.com/t/spawn-destroy-exact-amount-of-actors-per-tick-to-not-cause-any-performance-lack/2131052 "2024-11-17T15:02:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bor\_kor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@bor\_kor](https://forums.unrealengine.com/u/bor_kor)\
**Post date:** [November 17, 2024, 3:02pm UTC](https://forums.unrealengine.com/t/spawn-destroy-exact-amount-of-actors-per-tick-to-not-cause-any-performance-lack/2131052/1 "2024-11-17T15:02:12Z")

</div>

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](https://dev.epicgames.com/documentation/en-us/unreal-engine/tasks-systems-in-unreal-engine?application_version=5.5), 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:

```auto
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:

```auto
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.
