godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.54k stars 20.27k forks source link

CollisionPolygon2D doesn't expose an RID property #97544

Open Ughuuu opened 2 hours ago

Ughuuu commented 2 hours ago

Tested versions

4.3

System information

macos

Issue description

It is impossible to get the RID of a CollisionPolygon2D right now. Any other thing has a way to get RID property, which let you access directly the PhysicsServer2D if you want with that RID. Except the CollisionPolygon2D.

Steps to reproduce

Create a CollisionPolygon2D node. There is no get_rid() property.

Minimal reproduction project (MRP)

-

Ughuuu commented 2 hours ago

As a workaround I try to get the RID by doing something like this:

var parent = node.get_parent()
if parent is CollisionObject2D:
var idx = 0
for child in parent.get_children():
    if child == node:
        break
    idx += 1
rid = PhysicsServer2D.body_get_shape(parent.get_rid(), idx)

However this doesn't work for cases where the shape isn't parented to a CollisionObject2D or when it's disabled.

smix8 commented 40 minutes ago

A CollisionPolygon2D does not have a get_rid() function because it has no RID as it is not a CollisionObject2D.

A CollisionPolygon2D is a helper node for a parent CollisionObject2D node, so it is mostly dysfunctional without such parent.