Skip to main content

soft_body_removal

Removing a soft-body (PhysicsWorld::remove_soft_bodyi.e., despawning its entity, or removing its SoftBody componentWorld.removeSoftBodyr3RemoveSoftBodyPhysicsWorld.remove_soft_body) removes everything the engine created for it: its root body, the proxies of its clusters, the colliders of its surface and of its deformable meshes, as well as the joints attached to any of them. One cluster can also be removed on its own (PhysicsWorld::remove_soft_body_clusterby despawning its entity, or removing its SoftBodyCluster componentWorld.removeSoftBodyClusterr3SoftBody_RemoveClusterPhysicsWorld.remove_soft_body_cluster):

// Removing a soft body removes its root body, its proxies, its colliders and the joints
// attached to them.
world.remove_soft_body(rope_handle);
// A cluster can be removed on its own.
world.remove_soft_body_cluster(jelly_handle, cluster);
// Removing a soft body removes its root body, its proxies, its colliders and the joints
// attached to them.
world.removeSoftBody(rope);
// A cluster can be removed on its own.
world.removeSoftBodyCluster(jelly, cluster);
fn remove_soft_bodies(
mut commands: Commands,
rope: Single<Entity, With<Rope>>,
cluster: Single<Entity, With<PlateCluster>>,
) {
// Despawning a soft-body entity (or removing its `SoftBody` component) removes its root
// body, its proxies, its colliders and the joints attached to them.
commands.entity(*rope).despawn();
// Despawning a cluster entity (or removing its `SoftBodyCluster` component) removes the
// cluster.
commands.entity(*cluster).despawn();
}
// Removing a soft-body removes its root body, its proxies, its colliders and the joints
// attached to them.
r2RemoveSoftBody(rope_handle);
// A cluster can be removed on its own.
r2SoftBody_RemoveCluster(jelly_handle, cluster);
# Removing a soft body removes its root body, its proxies, its colliders and the joints
# attached to them.
world.remove_soft_body(rope_handle)
# A cluster can be removed on its own.
world.remove_soft_body_cluster(jelly_handle, cluster)
warning

Removing a cluster also removes the particles that only this cluster covered, with their elements and their attachments. Therefore removing the last cluster of a soft-body removes the soft-body itself. Note that removing the proxy of a cluster from the rigid-body setwith r3RemoveRigidBody (with PhysicsWorld.remove_body, or with RigidBodySet.remove given the soft-body set as its soft_bodies argument, without which it raises a ValueError) is equivalent to removing the cluster.