pub struct Previous<T: Component + Clone, S: ScheduleLabel + Clone = Last>(pub T, _);Expand description
A component that represents the previous value of another component T.
To enable previous-value-tracking for a component use PreviousPlugin.
The parameter S must be the same as the one specified in PreviousPlugin,
or be ommited, like with PreviousPlugin.
You don’t have to manually add Previous to your entity.
This is done automatically in the specified schedule S.
Also note that queries like Query<(&T, &Previous<T>)> won’t match entities
that were just created, as the may not have Previous yet.
Like with PreviousPlugin, there is a FixedMain type alias for it: FixedUpdate.
§Examples
#[derive(Component, Clone)]
struct Health(pub u32);
fn main() {
App::new()
.add_plugins(PreviousPlugin::<Health>::default())
.add_systems(Update, print_differences)
.run();
}
fn print_differences(query: Query<(&Health, &Previous<Health>), Changed<Health>>) {
for (health, previous_health) in &query {
println!("Health reduced by {}", previous_health.0.0 - health.0);
}
}With custom schedule:
#[derive(Component, Clone)]
struct Health(pub u32);
#[derive(DefaultSchedule, ScheduleLabel, Debug, Clone, Hash, PartialEq, Eq)]
struct AfterGameLogic;
// create a type alias to reduce boilerplate
type Previous<T> = bevy_previous::Previous<T, AfterGameLogic>;
fn main() {
App::new()
.add_plugins(PreviousPlugin::<Health, AfterGameLogic>::default())
.add_systems(GameLogic, print_differences)
.run();
}
fn print_differences(query: Query<(&Health, &Previous<Health>), Changed<Health>>) {
for (health, previous_health) in &query {
println!("Health reduced by {}", previous_health.0.0 - health.0);
}
}Tuple Fields§
§0: TImplementations§
Trait Implementations§
Source§impl<T: Clone + Component + Clone, S: Clone + ScheduleLabel + Clone> Clone for Previous<T, S>
impl<T: Clone + Component + Clone, S: Clone + ScheduleLabel + Clone> Clone for Previous<T, S>
Source§impl<T: Component + Clone, S: ScheduleLabel + Clone> Component for Previous<T, S>
impl<T: Component + Clone, S: ScheduleLabel + Clone> Component for Previous<T, S>
Source§const STORAGE_TYPE: StorageType = bevy::ecs::component::StorageType::Table
const STORAGE_TYPE: StorageType = bevy::ecs::component::StorageType::Table
A constant indicating the storage type used for this component.
Source§fn register_component_hooks(_hooks: &mut ComponentHooks)
fn register_component_hooks(_hooks: &mut ComponentHooks)
Called when registering this component, allowing mutable access to its
ComponentHooks.Source§impl<T: Debug + Component + Clone, S: Debug + ScheduleLabel + Clone> Debug for Previous<T, S>
impl<T: Debug + Component + Clone, S: Debug + ScheduleLabel + Clone> Debug for Previous<T, S>
Source§impl<'de, T, S: ScheduleLabel + Clone> Deserialize<'de> for Previous<T, S>
impl<'de, T, S: ScheduleLabel + Clone> Deserialize<'de> for Previous<T, S>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T: Ord + Component + Clone, S: Ord + ScheduleLabel + Clone> Ord for Previous<T, S>
impl<T: Ord + Component + Clone, S: Ord + ScheduleLabel + Clone> Ord for Previous<T, S>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialEq + Component + Clone, S: PartialEq + ScheduleLabel + Clone> PartialEq for Previous<T, S>
impl<T: PartialEq + Component + Clone, S: PartialEq + ScheduleLabel + Clone> PartialEq for Previous<T, S>
Source§impl<T: PartialOrd + Component + Clone, S: PartialOrd + ScheduleLabel + Clone> PartialOrd for Previous<T, S>
impl<T: PartialOrd + Component + Clone, S: PartialOrd + ScheduleLabel + Clone> PartialOrd for Previous<T, S>
impl<T: Eq + Component + Clone, S: Eq + ScheduleLabel + Clone> Eq for Previous<T, S>
impl<T: Component + Clone, S: ScheduleLabel + Clone> StructuralPartialEq for Previous<T, S>
Auto Trait Implementations§
impl<T, S> Freeze for Previous<T, S>where
T: Freeze,
impl<T, S> RefUnwindSafe for Previous<T, S>where
T: RefUnwindSafe,
S: RefUnwindSafe,
impl<T, S> Send for Previous<T, S>
impl<T, S> Sync for Previous<T, S>
impl<T, S> Unpin for Previous<T, S>
impl<T, S> UnwindSafe for Previous<T, S>where
T: UnwindSafe,
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId), )
unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
Source§fn get_component_ids(
components: &Components,
ids: &mut impl FnMut(Option<ComponentId>),
)
fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
fn get_components(self, func: &mut impl FnMut(StorageType, OwningPtr<'_>))
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.