That's highly unlikely ๐ But who knows, I well might be.
The engine cannot easily tell if an object is behind other object. Even if an objects is totally covered, it will still go through the rendering pipeline and it will be rasterized into pixels. Those pixels may or may not be drawn into final framebuffer, depending on what's in the depth buffer at the time of rasterization, but they will be processed nevertheless. This all happens in the graphics card on the pixel level and your script code has no easy way of concluding if an object is "behind" something.
In general there are 3 ways to completely skip pushing an object through the rendering pipeline. Their main purpose is performance optimization:
- explicit visibility toggle - this is self explanatory.
- frustum culling - object is checked against camera's viewing volume. It will be skipped if it's outside of it.
- occlusion culling - object is checked for occlusion by other objects in the scene which need to be specially assigned occluders. Those are typically some big, dominant elements in the scene.
The first two are straightforward and are routinely performed by most engines. The third one is tricky, can be computationally expensive and requires a special setup. Godot 4 can do occlusion culling but you'll need to set things up for every particular scene.
Godot can also notify you when object's visibility changes via VisibleOnScreenNotifier3D. It works for frustum culling but I'm not sure if it takes occlusion culling into consideration. You'll need to test it.
Afaik Unreal's WasRecentlyRendered() only works for frustum culling as well.
As suggested by @axolotl, you could set up an approximative test using raycasts, which would probably be an optimal solution for your needs.