Lecture 3: Entity Component Systems Flashcards

(20 cards)

1
Q

DOTS

What does DOTS consist of?

A

DOTS consists of:
* Entity Component Systems: ECS implementation in Unity
* C# Job System: fast, safe and easy multi-threading
* Burst: Compiler for HPC#
* Collections: NativeCollections for use with jobs
* Mathematics: SIMD friendly math library for jobs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

DOTS: Jobs

What is a Job?

A

To put it simply, it’s the logic on the main thread that is being split into smaller tasks called “jobs”.

In Unity specifically, the Unity Job System puts the jobs into a queue. A pool of worker threads can then draw from that queue and process the jobs.

Jobs have to Scheduled on the main thread. When scheduling a job, the job will not necessarily finish within the same frame unless said so.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

DOTS: ECS

What is Monobehaviour?

A

Monobehaviour is the standard Unity component that you get without downloading any packages.

Monobehaviour always exists as a Component of a GameObject and can be instantiated with GameObjects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

DOTS: ECS

What is a GameObject?

A

GamObjects are essential objects in Unity. They are objects that does not do much themselves but acts as containers for Components.

Components can bring the objects to life depending on the implementation.

GameObjects can be a child of another and through that has access to different callbacks and other methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

DOTS: ECS

What are the drawbacks of GameObjects?

A

GameObjects are managed objects and cannot be used in burst-compiled code.
The managed objects are garbage collected but also are scattered around memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

DOTS: ECS

What is ECS?

A

In bigger picture ECS stands for Entity, Component and Systems.

Entity is the ID
Component is the Data
Systems is the logic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

DOTS: ECS

What are Sub Scenes?

A

Sub scenes are a different scene type that essentially is a container that is converted into entity data. The GameObjects placed here are baked to DOTS data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

DOTS: ECS

What are Entities?

A

Entities should just be thought of as indexes. They are uniquely identified by a combination of index and version number.

An entity can have any number of components as long as it doesn’t have more than one of each component type.

An entities set of components is its Archetype.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

DOTS: ECS

What are Entity Archetype?

A

Entities that a share the same unique set of components are set to belong to the same Archetype.

In example:
Entity A: Position, Rotation, Renderer & Speed
Entity B: Position, Rotation, Renderer & Speed
Entity C: Position, Rotation & Renderer

Entity A and B belong to the same Archetype.
Entity C belong to one Archetype.

Entities with the same Archetype are stored together in memory in chunks.

When the user creates entities and gives them components; Unity manages the chunk in native memory*.

*native memory is the memory managed by OS for process

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

DOTS: ECS

What is a EntityManager?

A

EntityMananger is the central API for:
* Creating and Deleting entities
* Add and Remove Components

All of these are called structural changes and has performance implications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Managed vs Unmanaged Code

What is Managed code?

A

Managed code is essentially a programming language that handles memory management, exception handling and other tasks on the low level systems.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Managed vs Unmanaged Code

What is Unmanaged Code?

A

Unmanaged Code is code that runs directly on the OS - basically the opposite of Managed Code.

No handling of memory management, exception handling and other low level system tasks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Blittable and Non-blittable types

What is a Blittable type and can you name a few?

A

A Blittable data type are types that do not need to be marshalled when transferred between the two environments*.

Common Blittable types:
* float
* int
* double
* char
* bool
* structure (with blittable types)

*managed and unmanaged code environment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Blittable and Non-blittable types

What is Marshalling data?

A

Marshalling data is a process that converts data between managed and unmanaged environment.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Blittable and Non-blittable types

What is Non-blittable types and can you name a few?

A

Non-blittable data types are the types that do not have a consistent memory layout between the two environments*.

They need to be marshalled if you need to pass them between e.g. C# and C++.

*managed and unmanaged code enviroment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

DOTS: ECS

What are Components?

A

Components are structs though there are different types of Components but mainly it is structs. They do not contain any logic but only holds data, blittable data.

The types of Components are:
* General Purpose Component: contains only blittable data types but can hold multiple of them
* Tag Component: this component helps to specify archetype and the struct is often empty for optimization purposes
* Class Component: this component type is made with a class instead of struct. The reason why you may use this is in order to reference managed objects, though it has performance limitations and can only be used on main thread
* Dynamic Buffers: essentially stores data that are dynamic - the arrays are not shared between entities

17
Q

Baking

What is Baking?

A

Baking is the process of serializing data from the editor down to binary format.

We can use it to add additional data for when gameobjects in subscenes gets converted to entity data. We can also create components and entities in runtime via baking.

18
Q

DOTS: ECS

What is a System?

A

A System is a set of Data Transformation. Systems contain pure logic and little to no state. Each system has a system entity that processes all entities matching its queries.

Systems can be compared to the Start(), Update() and OnDestroy() in Monobehaviour.

Uses queries to only target specific set of entities.

19
Q

DOTS: ECS

What is a Query in ECS?

A

ECS introduces something called Idiomatic Foreach (IFE) that takes care of main thread code - but also has IJobEntity which does jobified multithreaded code.

IFE is important since since IFE will run and execute its logic on any Archetype that matches with the EntityQuery specified. EntityQuery checks all entities with a specified set of components (Archetype).

20
Q

Mathematics

What is MathF and math and the difference between them?

A

MathF is deal for non-bursted singlethreaded code or regular Monobehaviour code. It operate on single-precision float types and is mostly scalar-based (float, double, int). They do not support matrix operations or anything beyond 3D vectors directly.

math on the otherhand supports both scalar (float, double, int) and vectorized data types (float3, int4, quaternion). math is designed for high performance and efficiency, especially with Burst compilers which can auto vectorize operations (using SIMD). math is optimized to better auto-vectorisation and works great with burst compiler.