How to add nodes without lag to the scene

Godot Version



Hi, I’m loading a large node with a lot of tilemap tiles to my scene. Im doing this via the background loader. But once I add the node to my scene (add_child), it lags. I guess it needs to draw a lot of tiles. Is this wad? And how do I avoid it?

The background loading seems quite useless, its apparently only for reading/parsing the file on a separate thread.

Seems to be the same issue here?

I’m assuming that by lag, you’re saying that the game freezes for a short time while the scene is loaded and displayed.

Be sure you are instantiating your scenes inside the background thread. The vast majority of most delays while loading are actually in the instantiation rather than the transfer of data from storage. Don’t use add_child() from the background thread, as that operation is not thread-safe.

I have posted the core of a background loader I use in my game. You can see it in another question I answered: