Conversion WorkflowTo use Unity’s DOTS technology, you need to create entities, components and systems.The generation process that consumes GameObjects (authoring data) and generates entities and components (runtime data) is called conversion.
- This process is the preferred way of authoring ECS data
- It is a fundamental part of DOTS, and not something temporary
- Conversion is only about data, there is no conversion process for codeThe overall workflow looks like this:
- 1.The Unity Editor is a user interface to work with authoring data
- 2.The conversion from authoring data to runtime data happens in the Unity Editor
- 3.The runtime (e.g. the game) should only ever have to deal with runtime data
Fundamental principlesAuthoring data and runtime data are optimized for wildly different goals.
- Authoring data is optimized for flexibility
- Human understandability and editability
- Version control (mergeability, no duplication)
- Teamwork organization
- Runtime data is optimized for performance
- Cache efficiency
- Loading time and streaming
- Distribution sizeA key observation is that nothing requires a 1:1 mapping between GameObjects and entities.
- A single GameObject can turn into a set of entities, e.g. procedural generation
- Multiple GameObjects can be aggregated into a single entity, e.g. LOD baking
- Some GameObjects might have no purpose at runtime, e.g. level editing markersThe same can be said about components. A conversion system can read from any amount of Unity components and add any amount of ECS components to any amount of entities.
Key conceptsAll those concepts get explained in further detail in the rest of this document, but it's useful to introduce some vocabulary beforehand.
- Authoring scene A regular Unity scene, containing GameObjects, destined to be converted to runtime data.
- Subscene A simple GameObject component that references an authoring scene and will either load the authoring scene (when the Subscene is in edit mode), or stream in the converted entity scene (when the Subscene is closed).
- Entity scene The result of converting an authoring scene. Because entity scenes are the output of an asset import, they are stored in the Library folder. Entity scenes can be made of multiple sections, and each of those can be independently loaded.
- LiveConversion When an authoring scene is loaded as GameObjects for editing, every change will trigger an update to the entity scene, making it look as if the entity scene was directly edited, we call this process LiveConversion.
Make sure to first clear the file before pasting in this code snippet.
[GenerateAuthoringComponent]to add IComponentData directly on GameObjects
git clone https://github.com/moetsi/Unity-DOTS-Multiplayer-XR-Sample/ git checkout 'Setting-up-a-Project-for-ECS'