godotengine / godotengine/godot-docs

Physics2DShapeQueryParameters exclude parameter returns a copy instead of access to the Array

Open
#4,088 9 comments 0 reactions 0 assignees View on GitHub
area:class reference bug
Dominant language
reStructuredText
Stars
5.7k
Forks
3.8k
Avg merge
1d 20h
Merged PRs (30d)
25

Description

**Godot version:**
3.2.2.stable.mono.official

**Issue description:**
It's a confusing mixed issue, so following is more a description of the sequence of discoveries.
GetRestInfo() from PhysicsDirectSpaceState reports a collision with a KinematicBody as collider_id.
But excluding the kinematicbody is not directly possible. And adding the shape from the child CollisionShape to the exclude list also doesn't make it ignore it.
The next logical attempt is to use ShapeOwnerGetShape as mentioned in the docs to retrieve a shape from the body.
But there's no clear usable path for retrieving the 'actual shape' as mentioned there.
ShapeOwnerGetShape takes an ownerID and a shapeID, both are nowhere directly accessible.
Iterating GetShapeOwners() yields integers that apparently are shapeOwnerIDs.
There's another method ShapeOwnerGetOwner that takes an ownerID and should return an owner object.
The initial problem is that this method takes a uint, so it appears the available numbers from GetShapwOwners() are not expected here.
But using them (casted) atleast returns objects.
But those objects, if printed, reveal to be the CollisionShapes.
There's another method that returns a shape's index given its id, but no method that actually returns the id, so most other methods cannot be used.

So the problem is: It _seems_ that there is a way to exclude the KinematicBody in the query, but to do so, one needs to retrieve its shapeID with no method existing to do so.
It's possible that the exclude list actually just wants RIDs (not shapeids) and is just not working correctly (and if that's the case then the documentation of CollisionShape is also confusing).

All of these are **not** achieving the desired result (called from KinematicBody, GetRestInfo() returns the KinematicBody's instanceID as collider_id, which btw is also an int but should be long if it represents the instanceID):
queryParams.Exclude.Add(this);
queryParams.Exclude.Add(GetRid());
queryParams.Exclude.Add(GetInstanceId());
queryParams.Exclude.Add(collider.GetInstanceId());
queryParams.Exclude.Add(collider.Shape);
queryParams.Exclude.Add(collider.Shape.GetInstanceId());
queryParams.Exclude.Add(collider.Shape.GetRid());

**Minimal reproduction project:**
This demonstrates the exclusion not working:
[QueryFail.zip](https://github.com/godotengine/godot/files/4840886/QueryFail.zip)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.