Download Tutorial C Files H Files

dg_entity_free_component

This function is used to free a component from an entity.

Usage

void dg_entity_free_component(dg_entity_t *entity, char *name);

Example

dg_entity_free_component(entity, "score");

Source code

void dg_entity_free_component(dg_entity_t *entity, char *name)
{
    int comp = -1;
    dg_component_t *component = 0;

    if (!entity || !name)
        return;
    comp = dg_entity_has_component(entity, name);
    if (comp == -1)
        return;
    component = dg_arr_remove_at(&(entity->components), comp);
    dg_component_destroy(component);
}