Does Godot automatically load and unload tiles for you?

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

If I have a world that is 1500 by 5000 tiles does Godot automatically load and unload the tiles. In games like Minecraft the game loads chunks and then when you walk away the chunks unload. Does godot do this? If not how can I do this?

:bust_in_silhouette: Reply From: Zylann

No, Godot does not do that. If you have a huge tilemap or many nodes, it will attempt to not draw those outside the screen, but they are still present in the scene (and as such, accessible by scripts and they also run their logic if they have some).

If you want to do this you may figure out yourself how and when you want this to happen, and it heavily depends on how your game works. You may also make sure your game can cope with the fact that “not the entire world is available at a given time, and any part of it could be unloaded and reloaded at any time”. You may decide if this is actually what you need.
In the case of Minecraft, the game constantly iterates through a grid of chunks, the “loaded area”. If a chunk gets outside that grid, the game unloads it (saves it to a file). If a cell of the grid has no chunk, the game will load it (from the same kind of file, if it exists, otherwise it generates). Then this can be placed into a “task list” of chunks to load/unload to spread the load over frames, which could use threads etc.