godotengine / godotengine/godot

RenderingServer.instances_cull_aabb not reliable

Open
#87,709 5 comments 0 reactions 0 assignees View on GitHub
documentation topic:3d topic:rendering
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:
![image](https://github.com/godotengine/godot/assets/392218/38357ad6-7fc7-494e-b04a-6c8230fec83f)

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

![Screenshot from 2024-01-29 19-30-59](https://github.com/godotengine/godot/assets/392218/9dd45985-8573-4415-b549-b105f4b76d12)

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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.