Unity DOTS Component Overview

Recently, DOTS has finally released its official version. Let’s share a few key concepts in DOTS below to help everyone get started and learn and master Unity DOTS development.

Entity as an entity in Unity DOTS does not store data directly, but stores data in individual components as carriers. Each Entity will get some different combinations of ComponentData, which represent different Entity types. The object describing these combinations is called ArchType. Component contains the data in Entity and provides read and write access to System.

When we define a Component, we need to inherit the IcomponentData interface class. IcomponentData has no methods defined, it just marks this structure type as a component class of ComponentData in ECS. When we use struct to define ComponentData, it means that we are using an unmanaged (garbage collection) object, and the data members inside also need to be unmanaged. If you want to use managed data members and objects, you can Change struct to class to define.

Component's memory is based on Chunk (16kib) to allocate memory of a specific ArchType size (memory size after combining different components). Component belongs to a certain part of this memory block. For example, an Entity of type A is composed of A, B, and C components, then ArchType is [A, B, C] ArchType is the sum of each component. Through Chunk, allocate an ArchType memory, so that a certain ComponentData of Entity is a part of this memory block.

Chunk(16Kib): 【[A, B, C, …],[A, B, C, …],[A, B, C, …],[A, B, C, …],[A, B, C, …]】

There are several commonly used Component types that we commonly use in DOTS development, summarized as follows:

Unmanaged Component: The most commonly used unmanaged component type, but the data members inside must be unmanaged, so the types are limited.

Managed Component: A component type that can be managed, and the data members inside can also be of any type;

Shared Component: Multiple Entity instances share the memory of a ComponentData.

Cleanup Component: If one of our Entities has a CleanupComponent, when we destroy an Entity, all other components will be cleaned up.

Tag Component: An unmanaged component object that functions as a tag. You can use tag component to filter Entities.

Buffer Component: Defines an array data that can change the size of the array.

Enable Component: You can enable/disable a component instead of changing the ArchType of the entity like the Remove component, because changing the ArchType consumes very much performance.

For more Unity DOTS documentation, you can follow us to obtain relevant learning materials and code.

Guess you like

Origin blog.csdn.net/voidinit/article/details/133889806