How to Spawn Prefabs in ECS

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.

Click Here for DOTS Tutorial

Stop struggling with the limited documentation. Follow this step-by-step tutorial: "How to Spawn Prefabs in ECS."

Full workflows and code to programmatically spawn prefab entities

Click Here for DOTS Tutorial

This gitbook takes you through step-by-step full workflows and code to programmatically spawn prefab entities. Once you've coded along and fully finished the "How To Spawn Prefabs" tutorial, you will be able to programmatically spawn prefab entities.

Click Here for DOTS Tutorial

High-Level steps to Spawn Prefabs:

Number 01

Create a prefab and give it an authoring component

Number 02

Create an empty GameObject that will hold all references to prefabs

Number 03

Create a spawning system which spawns entities of a given height, width, and depth

FAQ

What is an Entity in ECS?

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 ECS?

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 ECS?

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.

Get Started