Object culling in 2d

Godot Version

Godot 4.4

Question

I’m currently making a 2d platformer. I’m building the world to not have any loading scenes. The way I’m doing this is by making each small level and then dragging it into the main scene. I know that having many scenes loaded can cause lots of strain on computers so I was looking into occlusion culling. I only managed to find a node to help with occlusion culling in 2d so I was wondering if there was a manual way to unload scenes and if so, how to unload ones that are further than X amount away. I’m not planning on having levels that are a set amount so that has been complicating and if that would complicate this I just wanted to put that out there. I am happy to answer any questions about my project and other things like that.

(Google translator)
I’m no expert but I don’t see the point in including all your levels in the same scene.
Regardless of whether something like occlusion culling existed in 2d, I think that would only affect the rendering pipeline. All the nodes of your levels, even if they were not visible, would execute their methods _process, _input, etc., just because they are inside the tree.
In the Godot documentation you can see how to change from one scene to another, for example: https://docs.godotengine.org/en/latest/tutorials/scripting/change_scenes_manually.html
If you want the player to not have to wait for loading times, I think the simplest thing would be for when you reach a certain area (an area2d or something with a visibleNotifier) to create a “thread” that preloads the next level to have it available as soon as you need it. You will only add that new level to the main scene tree at the appropriate time.
In short, I think that what is convenient in these cases is to store in memory the next scene that is most likely to be accessed by the player.

1 Like

You could try setting the process mode to disabled and/or hide the node.

If you don’t intend for the player to go back to the previous scene, you can use queue_free().

1 Like