This repository has been archived by the owner on Jun 1, 2022. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theDetached
component to the query's components array.Use Cases:
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.
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.
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. Soworld.querySettings.defaultComponents.add(Not(Detached))
or something like it would let you register multiple default components.