Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusting Rigidbody2D collisionShape properties at runtime breaks signals. #331

Open
rthomas-private opened this issue Jan 5, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@rthomas-private
Copy link

rthomas-private commented Jan 5, 2025

Description

With RB2D and collisionshape2D created in the editor, adjusting the properties of the collisionshape2D shape with code breaks signalling for TileMap collisions. Signals like body_entered, body_shape_entered no longer trigger from the RigidBody2D for TileMap, TileMapLayer or other RigidBody2D collisions, although the physics still works. It does however still trigger for CharacterBody2D's.

In this particular instance, the collision shape is a CircleShape2D added to the RB2D in the editor and the radius is set on _ready(). Even if the radius is set to the same radius as it already is the behaviour is evident.

Creating the collision shape and then setting the property at runtime avoids this issue.
Not touching the properties with code avoids this issue.
Using godot built-in physics avoids this issue.

To Reproduce
New scene Node2D.
Add TileMapLayer, configure configure physics, add a short horizontal line of physics enabled tiles.
Add RigidBody2D and CollisionShape2D Circle Shape.
Set Solver > Contact Monitor to ON and Max reported contacts to 1

On RigidBody2D add script;

extends RigidBody2D
@onready var collision_shape_2d: CollisionShape2D = $CollisionShape2D

func _ready() -> void:
	var circle_shape = collision_shape_2d.shape as CircleShape2D
	circle_shape.radius = circle_shape.radius
	connect("body_shape_entered", Callable(_on_body_shape_entered))

func _on_body_shape_entered(_body_rid: RID, body: Node, _body_shape_index: int, _local_shape_index: int):
	print(self.name, " hit ", body.name)

Add another RigidBody2D, but don't create or assign a collisionShape.
Add script to the second RB2D;

extends RigidBody2D

func _ready() -> void:
	var newcollider = CollisionShape2D.new()
	var circleshape = CircleShape2D.new()
	circleshape.radius = 5
	newcollider.shape = circleshape
	add_child(newcollider)

	connect("body_shape_entered", Callable(_on_body_shape_entered))

func _on_body_shape_entered(_body_rid: RID, body: Node, _body_shape_index: int, _local_shape_index: int):
	print(self.name, " hit ", body.name)

Place the two RigidBody's above the tilemap and enable gravity for both.

Expected behavior

RigidBody2D should trigger body_entered and body_shape_entered signals for all collisions with collisionshapes including tilemaps and tilemaplayers even if the properties of a collision shape originally added in the editor are adjusted during runtime.

Environment:

  • OS: Win 11
  • Version: latest
  • Godot Version: 4.3 stable
  • Type: 2d

Example project(zip)
Uploading rapier_RB2D_repro.zip…

Please attach a zip with project where issue occurs. Remove the addons folder so that the size is less than 25 mb.

@rthomas-private rthomas-private added the bug Something isn't working label Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant