decline-cookies / anvil-unity-dots

Unity DOTS and ECS specific additions and extensions to Anvil
MIT License
4 stars 1 forks source link

Entity Lifecycle #194

Closed jkeon closed 1 year ago

jkeon commented 1 year ago

Adds the ability to track the lifecycle of entities based on component filters.

What is the current behaviour?

There isn't a nice way to do this.

What is the new behaviour?

Entities can come into a world in two ways.

  1. They are created.
  2. They are imported from another world.

The IEntityLifecycleStatus treats both of these cases as "Arrivals" and will give you access to a list of Arrivals for a given frame.

Entities can exit a world in two ways as well.

  1. They are destroyed.
  2. They are evicted to another world.

The IEntityLifecycleStatus treats both of these cases as "Departures" and will give you access to a list of Departures for a given frame.

There is a special case with destruction where an Entity has a ISystemStateComponent on it which results in the Entity not being destroyed until later on in the frame and thus not counting as a Departure.

By telling the EntityLifecycleStatusSystem to count CleanupEntities as Departures, those entities that are in the cleanup state will count as departures and be ignored when they are actually destroyed.

Coupled together this provides an efficient ground truth for building lookups or other data to know what entities are in play without having to handle the different cases separately for each instance.

What issues does this resolve?

What PRs does this depend on?

Does this introduce a breaking change?

jkeon commented 1 year ago

Edits made but most were just answered your questions. Happy to chat about them if that's prefered