Scene.DestroyEntity method

void DestroyEntity(Entity entity);

Description

Removes the entity and every component it carries. Existing Entity handles to it become invalid — check IsValid() before using them after a destroy.

Note: destroying an entity mid-iteration over a view is undefined. Collect handles into a list and destroy after the loop.

Parameters

entityEntityHandle of the entity to remove.

Example

std::vector<entt::entity> dead;
auto view = scene->GetRegistry().view<Thread::HealthComponent>();
for (auto e : view)
    if (view.get<Thread::HealthComponent>(e).HP <= 0.0f) dead.push_back(e);
for (auto e : dead) scene->DestroyEntity({ e, scene });

Scene.DestroyEntity metoda

void DestroyEntity(Entity entity);

Opis

Usuwa encję razem ze wszystkimi jej komponentami. Istniejące uchwyty Entity do niej przestają być ważne — po zniszczeniu sprawdź IsValid(), zanim ich użyjesz.

Uwaga: niszczenie encji w trakcie iteracji po widoku jest niezdefiniowane. Zbierz uchwyty do listy i niszcz po pętli.

Parametry

entityEntityUchwyt encji do usunięcia.

Przykład

std::vector<entt::entity> dead;
auto view = scene->GetRegistry().view<Thread::HealthComponent>();
for (auto e : view)
    if (view.get<Thread::HealthComponent>(e).HP <= 0.0f) dead.push_back(e);
for (auto e : dead) scene->DestroyEntity({ e, scene });