godotengine / godotengine/godot
RenderingServer.instances_cull_aabb not reliable
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
v4.3.dev2.official [352434668]
### System information
Godot v4.3.dev2 - Ubuntu 22.04.3 LTS 22.04 - X11 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2060 (nvidia; 535.154.05) - Intel(R) Core(TM) i5-9400F CPU @ 2.90GHz (6 Threads)
### Issue description
Using `RenderingServer.instances_cull_aabb` in a `@tool` to detect intersection is giving weird results.
My tree looks like this:

Both the MeshInstance3Ds have a BoxMesh resource of size (1,1,1)

The red box is my probe. In the script there is a start/stop toggle. Initially I would place the red cube and then hit start which would perform the RenderingServer.instances_cull_aabb call. It was not giving a reply I could understand. Sometimes it would show that there was a hit, other times not—while the boxes were clearly intersecting. The screenshot shows such a case.
I then wired the red cube to move down and continuously probe. Now toggling start will begin that process.
As the red cube moves down and overlaps, it only starts reporting overlap halfway through the other box and then the reporting continues until the red cube is almost three times further below.
### Steps to reproduce (UPDATED)
**In the editor, if you move any nodes** ( the meshes) around (i.e. translate them) that somehow sticks in a cache/array somewhere and the `RenderingServer.instances_cull_aabb` call immediately report that as a hit.
If you **hide/show** the node you moved, it seems to clear it from that cache and the detection works properly.
I confirmed this by making the gray cubes in code, using `instances_cull_aabb` (which worked) and then removing them by code. This works on each run.
So, the problem is something about the editor.
### Minimal reproduction project (MRP)
I have pushed to my demo repo here:
https://gitlab.com/dbat/server_area_issue
(Start the test_cull scene)
Contributor guide
Research direction
Open the linked minimal reproduction project and start the test_cull scene; inspect calls to RenderingServer.instances_cull_aabb while moving and hiding/showing meshes in the editor. Compare editor-created instances with code-created ones, and define done as consistent overlap results after transforms and visibility changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100