Crate bevy_ecs_markers
source ·Expand description
bevy_ecs_markers
is a helper for bevy_ecs which adds the support to mark entites.
§Features
- proc (default) — re-exports procedual macros from
bevy_ecs_markers_macros
- bevy_app (default) — Adds
bevy
(without default features) as a dependency and introduces a helper trait to easily init markers.
§Getting Started
EntityMarker
s can mark/label entities to easily retrieve them later on by its marker.
Those markers can either be struct
s or enum
s.
§Single Entity Markers
Single Entity Markers are markers that just hold one marked entity.
They can automaticly be created by deriving EntityMarker
(as long as the feature proc
is set) on a struct
.
§Example
#[derive(EntityMarker)]
pub struct CameraFollowTarget;
fn get_single(marker: Marker<CameraFollowTarget>, query: Query<(), With<PossibleTarget>>) {
if let Ok(target) = query.get(marker.id()) {
// ...
}
}
fn set_single(marker: MarkerMut<CameraFollowTarget>) {
let id = /* ... */;
marker.assign(id);
}
§Multi Entity Markers
Multi Entity Markers are markers that hold an entity per value.
These will be automaticly generated when deriving EntityMarker
(as long as the feature proc
is set) on an enum
.
§Example
#[derive(EntityMarker)]
pub enum Players {
Red,
Blue,
Green,
Yellow,
}
fn get_value(marker: Marker<Players>, query: Query<(), With<Player>>) {
if let Ok(target) = query.get_mut(marker[Players::Red].id()) {
// ...
}
}
fn set_value(marker: MarkerMut<Players>) {
let id = /* ... */;
marker[Players::Green].assign(id);
}
§Initializing Entity Markers
When using EntityMarker
s, don’t forget to initialize them via the World
or App
:
use bevy_ecs_markers::MarkerExt;
app.init_marker::<MyMarker>();
Modules§
Structs§
- This type holds one
MarkerSlot
per slot of the marker type. - A slot holding one
Entity
.
Traits§
- Declares a struct as a marker.