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

Change ColliderParent to a ColliderOf relationship and rework ColliderHierarchyPlugin #671

Merged
merged 5 commits into from
Mar 22, 2025

Conversation

Jondolf
Copy link
Owner

@Jondolf Jondolf commented Mar 22, 2025

Objective

ColliderParent should be a relationship for robustness and semantics, and to take advantage of automatic source tracking for rigid bodies.

The ColliderHierarchyPlugin also currently deals with both attaching colliders to rigid bodies and managing transforms. This would be good to split into separate plugins.

Solution

Rename ColliderParent to ColliderOf, make it a Relationship, and add a RigidBodyColliders component for the RelationshipTarget. Collider hierarchies are now managed via observers and hooks instead of systems.

Note that ColliderOf requires a custom Relationship implementation, because Bevy's default implementation does not allow relationships to point to themselves.

I also split the ColliderHierarchyPlugin into a ColliderHierarchyPlugin (manages ColliderOf relationships) and ColliderTransformPlugin (manages and propagates collider transforms).


Migration Guide

ColliderParent has been renamed to ColliderOf, and it is now a Relationship.

The transform management in ColliderHierarchyPlugin has been extracted into a new ColliderTransformPlugin. The ColliderHierarchyPlugin no longer takes a schedule.

@Jondolf Jondolf added C-Enhancement New feature or request A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality C-Breaking-Change This change removes or changes behavior or APIs, requiring users to adapt labels Mar 22, 2025
@Jondolf Jondolf added this to the 0.3 milestone Mar 22, 2025
@Jondolf Jondolf enabled auto-merge (squash) March 22, 2025 11:23
@Jondolf Jondolf merged commit fb0158d into main Mar 22, 2025
5 checks passed
@Jondolf Jondolf deleted the collider-of-relationship branch March 22, 2025 11:38
Jondolf added a commit that referenced this pull request Mar 24, 2025
# Objective

Fixes #676.

#671 changed the `ColliderParent` component to a `ColliderOf` relationship. Because Bevy does not normally allow relationships to point to their own entities, this required a partial manual implementation of the `Relationship` trait. However, I left the default `on_replace` implementation, which (as it turns out) panics if the target entity does not exist, which is possible when despawning an entity and the relationship points to itself.

## Solution

Manually implement `on_replace` in a non-panicking way. Also replace some panicking uses of `remove` with `try_remove`.

Ideally this would be fixed by Bevy allowing self-relationships though.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality C-Breaking-Change This change removes or changes behavior or APIs, requiring users to adapt C-Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant