pub trait Component: Sized + 'static {
fn name() -> &'static str { ... }
fn on_drop(&mut self, entity: EntityId, encoder: &mut ActionEncoder) { ... }
fn on_replace(
&mut self,
value: &Self,
entity: EntityId,
encoder: &mut ActionEncoder
) -> bool { ... }
fn borrows() -> Vec<ComponentBorrow>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
{ ... }
}
Expand description
Defines component properties and behavior. Types may implement this trait to act as components and support implicit self-registration.
Types that do not implement this trait may still be used as components.
They are called “external”, must be registered manually and require usage of
World::spawn_external
, World::insert_external
, and World::insert_external_bundle
methods that would panic
when component type is not yet registered. Even if the type happens to implement Component
trait.
Provided Methods
sourcefn on_drop(&mut self, entity: EntityId, encoder: &mut ActionEncoder)
fn on_drop(&mut self, entity: EntityId, encoder: &mut ActionEncoder)
Hook that is executed when entity with component is dropped.
sourcefn on_replace(
&mut self,
value: &Self,
entity: EntityId,
encoder: &mut ActionEncoder
) -> bool
fn on_replace(
&mut self,
value: &Self,
entity: EntityId,
encoder: &mut ActionEncoder
) -> bool
Hook that is executed whenever new value is assigned to the component.
If this method returns true
then on_remove
is executed for old value before assignment.