Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Detached Entities #170

Closed
wants to merge 1 commit into from
Closed

Detached Entities #170

wants to merge 1 commit into from

Conversation

robertlong
Copy link
Member

Detached entities are not processed by queries unless explicitly configured. Detached entities can be used for pending entities while loading, prefabs, and deactivating entities without removing them.

To create a detached entity, add the Detached component. That entity will then be ignored by all queries by default. If you want a query to match detached entities you can add the Detached component to the query's components array.

Use Cases:

  1. Loading Entities: If you are writing a system that loads resources such as an image or model and you don't want the entity to be processed by other systems until it finishes loading, you can create a detached entity. The loading systems will then process the detached entities and remove the detached component once all dependencies have been resolved.

  2. Prefabs: If you want to use an entity as a prefab and clone it to make copies, or use it as the base object for an Object Pool, you probably don't want the prefab entity to be processed.

  3. Deactivating Entities: Detaching an entity instead of removing it from the world may be desirable. For example in Mozilla Spoke, objects are added to an undo stack. An entity could be deactivated and then added to the undo stack so that it was not processed by systems. Culling systems are another example where you may want to detach an object based on distance.

Alternatives:

The detached entity feature is implemented by adding a default Not(Detached) component to each query. You may want additional filters that act in the same way. For example turning off and on entities based on what zone of a world you are in. Perhaps there's a way to create multiple tag components that are registered as default items in each query's components array. So world.querySettings.defaultComponents.add(Not(Detached)) or something like it would let you register multiple default components.

@robertlong
Copy link
Member Author

I don't think we're going to do this anymore, so I'm going to close this.

@robertlong robertlong closed this Sep 10, 2020
@fernandojsg fernandojsg deleted the feature/detached-entities branch May 6, 2022 16:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant