pub trait AddDistinctComponent {
    type Component;

    fn add_distinct_component_unchecked(
        &mut self,
        entity: EntityId,
        component: Self::Component
    ) -> bool; }
Expand description

Add component only if not already present.

Required Associated Types

Required Methods

Adds component to entity, multiple components can be added at the same time using a tuple.
If the entity already has this component, it won’t be replaced. Very useful if you want accurate modification tracking.
This function does not check entity is alive. It’s possible to add components to removed entities.
Use Entities::add_component if you’re unsure.

Returns true if the component was added.

Example
use shipyard::{AddDistinctComponent, Component, EntitiesViewMut, ViewMut, World};

#[derive(Component, PartialEq)]
struct U32(u32);

let world = World::new();

let (mut entities, mut u32s) = world.borrow::<(EntitiesViewMut, ViewMut<U32>)>().unwrap();
let entity = entities.add_entity((), ());

assert!(u32s.add_distinct_component_unchecked(entity, U32(0)));
assert!(!u32s.add_distinct_component_unchecked(entity, U32(0)));

Implementations on Foreign Types

Implementors