How to Destroy Prefabs in Unity DOTS
Unity Entities 0.50
Last Updated on: 6/24/2022

This will take you about 20 minutes in prep time if you don't have Unity set-up, and 30 minutes in coding and debug time.
Stop struggling with the limited documentation. Follow this step-by-step tutorial: "How to Destroy Prefabs in Unity DOTS."
Full workflows and code to programmatically destroy prefab entities

This gitbook takes you through step-by-step full workflows and code to programmatically destroy prefab entities. Once you've coded along and fully finished the "How To Destroy Prefabs" tutorial, you will be able to programmatically destroy prefab entities.
High-Level steps to Destroy Prefabs:
Decide on the "destroy conditions" of your entities (i.e. "destroy entities that leave the perimeter")
Create a system that adds a Destroy tag to those prefabs that will be destroyed
Create another system that destroys any prefabs that have a destroy tag
FAQ
What is an Entity in Unity DOTS?
An entity is a collection of components. Let's say there is an asteroid with a Translation component which is a float3 and denotes the asteroid's position in space. Updating the Entity's Translation component values is not a structural change. The Entity still has the same amount and types of components, just different values.
What is an Entity Prefab in Unity DOTS?
An entity prefab is nothing more than an entity with a Prefab tag and a LinkedEntityGroup. The former identifies the prefab and makes it invisible to all entity queries but the ones who explicitly include prefabs, and the latter links together a set of entities, since entity prefabs can be complex assemblies (equivalent to GameObject hierarchies).
What are system types in Unity DOTS?
SystemBase - this is the type of system used most of the time for runtime game play. The systems of this type will do things like provide movement to asteroids or Spawn/Destroy. ComponentSystemGroup - this is groupings of systems. GameObjectConversionSystem - We have interacted with these systems when working with our GameSettingsComponent and our SetGameSettingsSystem. These are used for hybrid development. EntityCommandBufferSystem -EntityCommandBufferSystems are used as "sync" points for structural changes to entities.
Haven’t begun learning Unity DOTS yet, and need to start at the very beginning?
If you haven't yet dipped your toes into learning Unity's new multithreaded Data-Oriented Technology Stack (DOTS), now is the time. You can start at the very beginning with Moetsi’s tutorial, which culminates in your very own deployable sample project. You’ll be guided by full workflows, code-alongs, videos, and GIFs along the way.
Whether you have questions about Unity's multithreaded Data-Oriented Technology Stack (DOTS), or about the RaaS API, or even just general questions about data-intensive pipelines for spatial computing applications, come join our Discord! We maintain a friendly channel, and we're always quick to respond.