In your video game, maybe you have a car that is moving or something. In that case, let's say, your car is going to have, you know, velocity, the speed, right, you're going to have a speed, you're going to have a position, like, where your car currently is at. All those two things are kind of your components, right, your velocity and your position, they are components. But the car itself, which is, you know, going to be like, you know, a certain car is going to have a velocity, is going to have a position, is going to have a color, the car itself is going to be an entity, because it's basically just, you know, a collection of different components brought together. So basically, that is the main concept behind ECS.
We basically want to separate, you know, different, you want to separate the different behavior and data in your games into components. And in that way, it is easy for you to, it is basically easy for you to, you know, pick any components that you need. You know, when building like an entity or to bring it down an object in your game, it's easy for you to, you know, just pick different components, you know, as part of the entities. And you basically like, you know, built a new, you know, a new object to your game, like straight out of the box. So, and basically, entities are unique identifiers, like I mentioned, and components are just data that are attached to the entities.
Now talking about systems, systems are on the other hand, is basically just a collection of entities and components that perform a specific task. So, just to, again, using that analogy. So, let's assume that in a situation where you have maybe, you want to perform a task, let's say in the case of a video game, right, where you have like a car, your video game and you want to basically, let's say, move the car. So, in that situation, the only component that you really need to perform that task is, let's say, position and velocity, right? So, in this case, you probably don't have any interest in, you know, maybe the colour of the car or how big the car is because they don't affect the particular task that you want to perform at that particular time, right? So, basically, what the system does is they are basically just like, sort of, functions that help you, like, separate, like, specific tasks and the certain components that are related for you to actually perform the task. And, basically, in the long run, what it just does is it makes it easier for you to, you know, manage your code, makes your code, like, more manageable.
So, and how, basically, how does ECS work? So, entities are created and destroyed at runtime by your game engine. So, entities are basically just objects in your games. You add components, your game engine adds, you know, or removes components from it at runtime. That is from your entities, right? And then your systems are updated at regular, you know, intervals, you know, depending on the operations that you perform or that the user performs within the games. So, why is ECS such a popular, you know, it's a very popular game development architecture, right? And why is that so? It is a good choice for game development because one, it promotes code reuse, right? I mean, like we explained earlier, you have, you know, specifically defined components, which means, like, you can easily grab a component and attach it to different entities, actually, not just one type of entities. You can you can easily create a modified game object. Like, basically, all you have to do is just, you know, you define game entity and just create a new one, attach some component to it. And it can also help to support efficient data access, just like, you know, separation of, like, all your data into well-defined components. And it can easily be scaled, you know, as your game gets bigger, you can easily scale it.
Just to add, like, a little code example, just to put some sense into what I've been talking about so far. So, in this example here, you can see you have, you have a position component, you have a velocity component. And your position component, you can see, like, basically, you just have your X and Y axis, right? And your velocity component, as well, you have your X and Y axis. And then you have your movement system. And those, okay, just going back. The components, like, you see, they basically, I'm not doing anything besides just representing a component.
Comments