Adding an instanced large TileMap with add_child results in a lag spike

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Jatoxo

I have a TileMap in my Scene which I store in a variable and then remove from the scene tree with “remove_child”.
I then create a Thread to fill the tilemap with a large number of cells to create my world.
When the thread finishes, I add the TileMap back into the scene with “add_child”, but this causes the game to freeze for several seconds.

Is there any way to avoid this lag but still be able to use a Thread to fill the TileMap? Since you can’t access the scene tree from a Thread I don’t see how…

Can you try calling the add_child method inside a call_deferred method?

nightrobin | 2021-03-05 15:18

It already was inside of a call_deferred method, called by the thread at the end when it is done adding tiles

Jatoxo | 2021-03-05 21:35

Hey, did you ever find a solution to this? I have tried multiple methods at this point. chunking as a small part of a bigger TileMap. Chunking as a larger map but each chunk has it’s own individual map. etc etc. I still get lag.