Skip to content

Change ColliderParent to a ColliderOf relationship and rework ColliderHierarchyPlugin#671

Merged
Jondolf merged 5 commits into
mainfrom
collider-of-relationship
Mar 22, 2025
Merged

Change ColliderParent to a ColliderOf relationship and rework ColliderHierarchyPlugin#671
Jondolf merged 5 commits into
mainfrom
collider-of-relationship

Conversation

@Jondolf

@Jondolf Jondolf commented Mar 22, 2025

Copy link
Copy Markdown
Member

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-Feature A new feature, making something new possible A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality M-Migration-Guide A breaking change to Avian's public API that needs to be noted in a migration guide 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
@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-Feature A new feature, making something new possible M-Migration-Guide A breaking change to Avian's public API that needs to be noted in a migration guide

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant