# Migrating From v0.5 to v0.6

## Broad Phase

PR [#927](https://github.com/avianphysics/avian/pull/927) overhauled broad phase collision detection
to use a Bounding Volume Hierarchy (BVH).

`BroadPhasePlugin` has been replaced by two plugins:

- `BroadPhaseCorePlugin`: Sets up resources, system sets, and diagnostics required for broad phase collision detection.
- `BvhBroadPhasePlugin`: Implements a broad phase using a BVH to efficiently find overlapping AABBs.

The latter can be swapped out for a custom broad phase implementation if desired.
See the documentation of the `broad_phase plugin for more information.

The `BroadPhaseSystems::UpdateStructures` system set has also been removed.
The BVH acceleration structures are updated by the `ColliderTreePlugin`,
in `ColliderTreeSystems::UpdateAabbs`.

Contact pair creation order can be different from before due to the new broad phase algorithm,
resulting in slightly changed behavior (but you should not rely on a specific contact order anyway).
The order should still be deterministic across runs, given the same inputs.

Previously, `ContactPair::body1` and `ContactPair::body2` also used the `Entity` of the collider
if the collider was not attached to a body. Now, the properties are instead `None`.

## Spatial Queries

PR [#941](https://github.com/avianphysics/avian/pull/941) changed spatial queries to reuse
the `ColliderTrees` used by the broad phase.

### Removed `SpatialQueryPipeline`

The `SpatialQueryPipeline` has been removed. Instead, use the `SpatialQuery` system parameter,
or for lower level control, use the `ColliderTrees` resource directly.

If you get query conflicts because `SpatialQuery` queries for `&Position` and `&Rotation` and your system
also queries for them mutably, consider deferring the mutation to a later point to avoid the conflict.

Previously, you could call `SpatialQuery::update_pipeline()` to update the internal acceleration structures
when you have made changes to colliders or their positions, and need to perform spatial queries before the next physics step.
This method no longer exists, but there is instead a public `update_moved_collider_aabbs` system that you can run.

### Shape Cast Data

Shape casts now return hits in arbitrary order when `max_hits > 1`, similar to ray casts.
This is for performance reasons.

Previously, `point2` in `ShapeHitData` was also relative to the shape cast origin,
even though documentation described it as a global point. This has been fixed,
and it is now in world space like the other values.

## Joint Motors

`RevoluteJoint` and `PrismaticJoimt` now store motors for driving movement.
By default, they are disabled, so this should not be a breaking change for most applications.

## `ReadRigidBodyForces` and `WriteRigidBodyForces`

PR [#908](https://github.com/avianphysics/avian/pull/908) introduced two new traits: `ReadRigidBodyForces` and `WriteRigidBodyForces`, and `RigidyBodyForces` is now defined as:

```rust
pub trait RigidBodyForces: ReadRigidBodyForces + WriteRigidBodyForces {}
```

In most cases this should just work, but if it doesn't, you can replace your implementation for `RigidBodyForces` with both `ReadRigidBodyForces` and `WriteRigidBodyForces` where it is used / needed. Both traits are required to implement `RigidBodyForces`, but you can implement them separately.

## Immutable `CollisionLayers` and `ActiveCollisionHooks`

The `CollisionLayers` and `ActiveCollisionHooks` components are now immutable
to reduce change detection overhead and enforce internal invariants more strictly.
To modify their values, reinsert the components with new values using `EntityCommands::insert`.

## `SleepBody` and `WakeBody`

The `SleepBody` and `WakeBody` commands now return an error when applied for an entity that doesn't exist
or doesn't belong to an island. Previously, they logged a warning instead.
