#bevy-plugin #exclusive #querying #define #set

bevy_exclusive_with

A Bevy plugin to define exclusive sets of components for ergonomic querying

1 unstable release

0.1.0 Feb 1, 2026

#623 in Game dev

MIT/Apache

18KB
142 lines

bevy_exclusive_with

License Build Status crates.io docs.rs

A Bevy plugin to define exclusive sets of components for ergonomic querying.

This can help you to define a set of components that should be mutually exclusive on entities, and then query for them in the same system without getting conflicts.
Caveat: This does not actually enforce the exclusivity when inserting/mutating components, but just helps you to query them without conflicts. A complete solution would require Archetype Invariants.

Usage

use bevy::prelude::*;
use bevy_exclusive_with::*;

// Some components you want to query exclusively
#[derive(Component)]
struct ArcherTower;

#[derive(Component)]
struct CannonTower;

#[derive(Component)]
struct MagicTower;

// Define the set of exclusive components
struct Towers;

exclusive_set!(Towers: ArcherTower, CannonTower, MagicTower);

// Query for them in the same system
fn system(
    _archer_towers: Query<&mut Transform, ExclusiveWith<Towers, ArcherTower>>,
    _cannon_towers: Query<&mut Transform, ExclusiveWith<Towers, CannonTower>>,
    _magic_towers: Query<&mut Transform, ExclusiveWith<Towers, MagicTower>>,
) {}

License

Licensed under either of

at your option.

Dependencies

~20–34MB
~551K SLoC