How to add nodes without lag to the scene

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:

1 Like