bevy_ecs/world/
component_constants.rs

1//! Internal components used by bevy with a fixed component id.
2//! Constants are used to skip [`TypeId`] lookups in hot paths.
3use super::*;
4use crate::{self as bevy_ecs};
5#[cfg(feature = "bevy_reflect")]
6use bevy_reflect::Reflect;
7
8/// [`ComponentId`] for [`OnAdd`]
9pub const ON_ADD: ComponentId = ComponentId::new(0);
10/// [`ComponentId`] for [`OnInsert`]
11pub const ON_INSERT: ComponentId = ComponentId::new(1);
12/// [`ComponentId`] for [`OnReplace`]
13pub const ON_REPLACE: ComponentId = ComponentId::new(2);
14/// [`ComponentId`] for [`OnRemove`]
15pub const ON_REMOVE: ComponentId = ComponentId::new(3);
16
17/// Trigger emitted when a component is added to an entity. See [`crate::component::ComponentHooks::on_add`]
18/// for more information.
19#[derive(Event, Debug)]
20#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
21#[cfg_attr(feature = "bevy_reflect", reflect(Debug))]
22pub struct OnAdd;
23
24/// Trigger emitted when a component is inserted onto an entity. See [`crate::component::ComponentHooks::on_insert`]
25/// for more information.
26#[derive(Event, Debug)]
27#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
28#[cfg_attr(feature = "bevy_reflect", reflect(Debug))]
29pub struct OnInsert;
30
31/// Trigger emitted when a component is replaced on an entity. See [`crate::component::ComponentHooks::on_replace`]
32/// for more information.
33#[derive(Event, Debug)]
34#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
35#[cfg_attr(feature = "bevy_reflect", reflect(Debug))]
36pub struct OnReplace;
37
38/// Trigger emitted when a component is removed from an entity. See [`crate::component::ComponentHooks::on_remove`]
39/// for more information.
40#[derive(Event, Debug)]
41#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
42#[cfg_attr(feature = "bevy_reflect", reflect(Debug))]
43pub struct OnRemove;