1.3 Understanding Unity - S Component System
1.3 Understanding Unity - S Component System
Component System
Learning Objectives
Understand the concept of Unity's component system.
Explore common components and their roles.
Grasp the significance of component-based design in Unity.
2
What is Unity's Component System
The Entity Component System (ECS) is the core of the Unity Data-Oriented Tech Stack (DOTS). As the
name indicates, ECS has three principal parts:
Components — the data associated with your entities, but organized by the data itself rather than by
entity. (This difference in organization is one of the key differences between an object-oriented and a
data-oriented design.)
Systems — the logic that transforms the component data from its current state to its next state— for
example, a system might update the positions of all moving entities by their velocity times the time
interval since the previous frame.
In a component system, objects exist on a flat hierarchy, and different objects have different collections
of components. An inheritance structure, in contrast, has different objects on completely different
branches of the tree. The component arrangement facilitates rapid prototyping, because you can quickly
mix and match components rather than having to refactor the inheritance chain when objects change.
1: Hocking, Joseph; Schell, Jesse, Unity in action: multiplatform game development in C#, 2022 4
What is Unity's Component System
Unity
ESC Game Objects
Entity
Unity Components: Transform, MeshFilter, Renderer,
Colider, Rigidbody, Script component
Component
RenderSystem: SpriteRenderer, MeshRenderer,
ParticleSystemRenderer
System
MovingSystem:
5
Components in Unity
In Unity, components come in various forms. They
can be for creating behavior, defining
appearance, and influencing other aspects of an
object's function in the game.
By attaching components to an object, you can
immediately apply new parts of the game engine
to your object. [10]
Components are one of the three principle elements of an Entity Component
System architecture. They represent the data of your game or program. [8]
To build further interactive elements of the game, you'll write scripts, which are also
treated as components in Unity. Try to think of a script as something that extends or
modifies the existing functionality available in Unity or creates behavior with the Unity
scripting classes provided. [10]
7
Common Components in Unity
Components Using / Datastore
Transform Position, Rotation, scale
The Rigidbody component controls the physics simulation of your GameObject. The
Rigidbody component simulates acceleration and velocity every FixedUpdate
(generally every 50th of a second) to update the position and rotation of the
Transform component over time. It also uses the Collider component to handle
collisions with other GameObjects. The Rigidbody component can also model things
like gravity, drag, and various forces like wind and explosions. Set isKinematic to
true if you want to directly set the position of your GameObject without using the
physics provided by Rigidbody.
1: Hocking, Joseph; Schell, Jesse, Unity in action: multiplatform game development in C#, 2022 14
Script Components
1: Hocking, Joseph; Schell, Jesse, Unity in action: multiplatform game development in C#, 2022 15
Advantages of Component-Based Design (CBD)
There are many advantages of developing the applications
using the CBD
4. Reusable − The use of reusable components means that they can be used to spread the development
and maintenance cost across several applications or systems.
16
Advantages of Component-Based Design (CBD)
5. Modification of technical complexity − A component modifies the complexity through the use
of a component container and its services.
6. Reliability − The overall system reliability increases since the reliability of each individual
component enhances the reliability of the whole system via reuse.
7. System maintenance and evolution − Easy to change and update the implementation without
affecting the rest of the system.
17
Practice – Assets folder structure
Hint: In order to organize the Assets folder, create the following folders:
Source: https://unity.com/how-to/organizing-your-project
18
Practice 1 – Create an enemy
1.Create an empty game object, reset its transform, and rename it
Goober (Enemy).
2.Add the Sprite Renderer component to Goober.
Drag and drop an image (SPA_Enemy_Right.png) into the
Sprite field.
Set the Sorting Layer to ‘Enemies’.
22
Practice 1 – Create an enemy
6. Add an Script component to 'Goober.'.
Select the 'Goober' GameObject, drag and drop the 'EnemyMovement.cs'
scipt into the Inspector window.
23
Practice 2 – Add Cinemachine Follow Camera
1. Import Cinemachine: Start by ensuring you've installed the Cinemachine package in your Unity project. You
can do this using the Package Manager (Window > Package Manager > Cinemachine).
24
Practice 2 – Add Cinemachine Follow Camera
2. Create a Virtual Camera: Right-click in the Hierarchy window, select
"Cinemachine" > "Virtual Camera". This creates a new Cinemachine virtual
camera.
Body: Framing Transposer
Follow: Goober (For testing. In real game, Virtual Camera should follow the
player).
Exploration of Common Components: Introduced vital components like
and importance.
Component-Based Design Advantages: Discussed the benefits—reusability,
26
References
1: Hocking, Joseph; Schell, Jesse, Unity in action: multiplatform game development in C#, 2022
3: Geig, Mike, Sams teach yourself Unity Game development in 24 hours, 2014
6: Gibson Bond, Jeremy, Introduction to Game Design, Prototyping, and Development: From Concept to
Playable Game with Unity and C,
27