Unload what you can't see

Godot Version 4.5.1

Question

Hello,

I am currently learning Godot and would like to know how to unload everything that the camera does not see, i.e., everything that my character is not looking at.

And the second thing is, for example, unloading the different floors of a house, because my game mainly takes place in one of the rooms of the house at the beginning, and I would like to know how to unload the other rooms.

Thank you.

Why would you want to do that? Do you have performance issues?

No, I’d like to know how to do it in case I need to and to learn…

Don’t load it in the first place.

You can remove nodes from the tree (hence unloading them from memory) by calling queue_free() on them.

It would be very impractical to do that on everything that your camera doesn’t see and then loading them back in when you rotate the camera, so I wouldn’t recommend doing that. In my couple of years working with Godot, I’ve never seen anyone having to do that and it might even sink your performance instead of helping it.

Chunking your scenes, e.g. by different rooms / levels - perfectly valid thing to do and you can just instantiate the scene and add it to the tree when you want it and queue_free when you don’t need it anymore.

Okay, thank you very much.

Do you have a tutorial, or if not, what is it called ?

So that I can do my research.

Thank you.

If you mean my last paragraph - then it’s just loading and unloading a scene into and from the tree, nothing too special. Any basic tutorial touches that topic, e.g.:

1 Like

You can use a VisibleOnScreenEnabler3D node to automatically enable/disable nodes on screen. You can also enable occlusion culling.

But if you are just starting then you shouldn’t worry about this.

2 Likes